Running code: Edge.find_faces returns 2. Is it possible to select the first face and execute a pushpull?
Thank you!
Edge#find_faces returns the number of new Faces that were created. Unfortunately, if there were pre-existing Faces associated with the Edge, the method does not tell you which ones were newly created and does not promise that the Array of Faces returned by Edge#faces is sorted in any particular order. So, you will have to fetch the Array and perform some sort of test on each Face (assuming there is more than one) to select the one that you mean by “first”. There are a lot of ways you might test, depending on the details of the model.
Thank you!
Van: Steve Baumgartner [mailto:sketchup@discoursemail.com]
Verzonden: dinsdag 31 januari 2017 16:18
Aan: roger.rosiers@gmail.com
Onderwerp: [SketchUp Forum] [Developers/Ruby API] Edge.find_faces
https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/45/7302_1.png
http://forums.sketchup.com/users/slbaumgartner slbaumgartner SketchUp Sage
January 31
Edge#find_faces returns the number of new Faces that were created. Unfortunately, if there were pre-existing Faces associated with the Edge, the method does not tell you which ones were newly created and does not promise that the Array of Faces returned by Edge#faces is sorted in any particular order. So, you will have to fetch the Array and perform some sort of test on each Face (assuming there is more than one) to select the one that you mean by “first”. There are a lot of ways you might test, depending on the details of the model.
If you are working within an entities context [like a group] then make an array of all existing faces:
extg_faces=entities.grep(Sketchup::Face)
Now use your:
edge.find_faces
Now find the new faces:
new_faces=entities.grep(Sketchup::Face)-extg_faces
Now lets assume you want the ONE face that has a vertical up normal
face=nil
new_faces.each{|f| if f.normal==Z_AXIS; face=f, break; end }
Of course there might be complications - like two matching new faces for that edge - so if you want both the collect those ‘faces’ instead, omit the ‘break’ thus
faces=[]
new_faces.each{|f| if f.normal==Z_AXIS; faces<<f; end }
then process each face in faces…
Note that if f.bounds.center z==0 && f.normal.parallel?(Z_AXIS) then f.normal==Z_AXIS.reverse ALWAYS, even those edges would normal create an upwards looking face at any other z value - this is as the built-in face generation when the order of edge creation has no affect and when located on the ground a new face always looks downwards, otherwise the clockwise/counter-clockwise edge generation can determine face orientation…