Over right the face class
-
Is there a way to over right the face class and add more functions to it?
What I’m trying to do is add a Boolean attribute generically to the face class called looked_at.
So that when i do my calculations i can check this variable and see if that face was looked at or not yet -
It is always a bad idea to overwrite an existing class. That will cause problems with other scripts in the future. There are ways to make your own class that is a subclass, or just make your own method for faces that examines the face and returns a value. That is safe.
-
@morci429 said:
Is there a way to over right the face class and add more functions to it?
What I’m trying to do is add a Boolean attribute generically to the face class called looked_at.
So that when i do my calculations i can check this variable and see if that face was looked at or not yetIt is possible to ADD methods to the Face class [or any class for that matter] but it's not recommended that you do this as if other scripters do the same thing with the same method name but different outcome in the method then disaster will ensue for one of you as one version won't work as expected...
That said, what you describe sounds wholly unsuitable for the Face class anyway - even if you had made such a method it would be set true/false 'generally' at each step, and not for a specific 'face'. If that's what you want a class variable
@@lookedat
would suffice within your own class, without recourse to messing with the premade classes...
What I think you really want is a tool that uses an attribute likeface.set_attribute("MorciDict","lookedat",true)
for a specific face...
You can add/change this attribute to any face that you tool encounters, and 'looks at'...
Later when you want to test for them or even to collect these together, you can make a set of all faces in the entities that have that attribute settrue
, thus.
lookedatfaces=[] model.active_entities.each{|e|lookedatfaces << e if e.class==Sketchup::Face and e.get_attribute("MorciDict","lookedat",false)}
Now you have an array of all faces that have been 'lookedat' ?I'm puzzled as to how you know a face has been 'lookedat' but that's another issue..........
-
Tig you are right, using AttributeDeictionary is the right way to go and does exactly what i need.
Thank you
Advertisement