Keeping track of a face
-
In a script, if I pushpull a selected face, face.pushpull dist,true, the new face is the last entity in the model. If I then rotate that face, it is still the last entity in the model. But if I scale the face, it is no longer the last entity and apparently has a new entityID as well. How can I keep track of or find this face?
-
Can you attach your own 'id' attribute to it [say id=Time.to_f] - this is [often] transfered across entities... not sure about faces though...
-
When I select the face, and assign a reference to it:
mod = Sketchup.active_model sel = mod.selection f = sel[0]
Then use the native scale tool..
f
still points to the same face object,
f.entityID
andf.__id__
remain unchanged. -
@sdmitch said:
How can ... find this face?
Where
ents
is someSketchup::Entities
collection instance:before = ents.find_all{|e| e.is_a?(Sketchup;;Face)} # do something that creates a new face(s) object HERE after = ents.find_all{|e| e.is_a?(Sketchup;;Face)} new_faces = after - before
new_faces
will be an array of faces created after thebefore
"snapshot". -
Dan, When the pushpull is executed there are n+1 faces created where n is the number of sides of the face so after-before will return the new faces but not the specific face. Since it is the new copy of the face that is created by the pushpull that I am interested in there is no way to to get its' ID since the pushpull operation returns nil and nothing more.
I misspoke earlier, the new face created by the pushpull is the first entity added to the file so saving the length of the model entities gives the index of the new face.
After further testing, it seems that the script works almost without fail in a empty model but often fails in a model that isn't. So back to the drawing board.
-
Well now I am confused about what you are doing because you indicated the problem was after a scaling.
-
Yes I thought it was but that, as it turns out, that is not the case. I was originally trying to run the script in a model that had other entities and the script failed after the scaling function when the face seemed to turn into an edge. But later, in an empty model, the script ran without a problem so the face was not "lost" as I first thought. I'm just as confused as you are now that it works sometimes.
-
When you pushpull a face the number of extra faces made in the model can be found - as discussed. Since the 'new face' [which from a user perspective is the 'original face' relocated along the face's normal] has the same normal as the original [which you can already have remembered in a reference] and none of the other new faces share this normal.
It gets messy unless your new geometry is being kept inside a group [even temporarily] because the pushpulled result might coincide with one or more preexisting faces that have the same [or reversed] normal as the original face and thereby several new faceS made could have matching normals but the preexisting ones now subsumed into the pushpulled form will be missed in any before/after ents comparisons. Therefore making the new geometry in a group is highly recommended... you can pushpull, get the new face by matching normals, then intersect the face with the model's entities and re-get all faces inside the group with matching normals. Thus what's in the group mimics what would have happened without any grouping BUT lets you collect all of the newly made faces, should any be split by [potential] merging with existing geometry...
Advertisement