[Resolved] How select a face created in another face?
-
Hello everyone
I am developing a plugin to make holes in a given geometry.
Select the face where I will apply this geometry and design lines that will make this hole.
How do via code, to capture that face created as a result of this new geometry that was drawn on the selected face?Thanks
-
` set1 = Sketchup.active_model.entities.to_a
create new geometry
set2 = Sketchup.active_model.entities.to_a
subtract set1 from set2
setnew = set2 - set1
facenew=false
setnew.each {|e| facenew=e if e.class==(Sketchup::Face) }`
That is a very simple example, it may be more complex if the face your 'carving' is within a Group or ComponentInstance.
-
@dan rathbun said:
facenew=false setnew.each {|e| facenew=e if e.class==(Sketchup::Face) }
what about:
facenew = setnew.select{|e| e.is_a?(Sketchup::Face)}
-
@thomthom said:
what about:
facenew = setnew.select{|e| e.is_a?(Sketchup::Face)}
Yes, but facenew WILL be an array, with possible more than 1 face.
The original poster would need to check .areaof each item in array, to determine which face was smaller and delete it.
-
You know the 'face' that will contain the new face - since you said you selected it.
Since you are creating new geometry you will know the 'edges' you have just added to the entities.
If you make a circle it returns the edges as an array. If the hole is some other shape you will be adding these so you can get references to them?
Any one of these new edges (e.g. edges[0]) should have two faces - the one that is NOT 'face' is the 'new face' ?
If there's a chance the new face won't be wholly on 'face' then if an inspected 'edge' doesn't include 'face' in its 'faces' then try processing more like this...### assume the selected face is called 'face' ### and new edges you've added are in an array called 'edges' newface=nil 0.upto(edges.length-1).each{|i| if edges[i].faces.include?(face) if edges[i].faces[1] edges[i].faces.each{|f| if f != face newface = f break end } end else next end } ### 'newface' is the new face or 'nil' if it's not on 'face' at all ### you can then find the new 'separate' face if desired... newface = edges[0].faces[0] if not newface ### 'newface' is found at last even if not on 'face' at all ! ### alternatively 'not newface' tells you it's missed face all together...
-
If you are using entities.add_face, the new face created is returned as the result. You can create the face with either lines (edges) or points. No big deal.
-
@unknownuser said:
If you are using entities.add_face, the new face created is returned as the result. You can create the face with either lines (edges) or points. No big deal.
Yes .. You're right.
This morning I could get tested and worked properly in this way.
Thanks
Advertisement