Find to which face a door belong
-
hello everyone,
i have a model and i need to detect which face contains a door, i managed to detect windows using the outer and inner loops but it doesn't work on doors as the door has an edge that is common between the face and the floor.
this is the code i use to detect windows and find to which face they belong:
model = Sketchup.active_model ents= model.active_entities ents.each do |f| if f.is_a? Sketchup;;Face inner_loops = (f.loops - [f.outer_loop]) nested_faces = [] inner_loops.each{|loop| loop.edges[0].faces.each{|e| nested_faces << e unless e == f } } if nested_faces.empty? UI.messagebox("Face; #{f.material.display_name} has no windows ") else nested_faces.each{|ff| UI.messagebox("Face; #{f.material.display_name} contains the window #{ff.material.display_name} ") } end end end
how can i change my code so that it detects doors also ?
thnx a lot.that's the model where i'm testing the doors' detection.
-
Please update your info to reflect that you are using version 2016.
If you assume that all walls and doors are vertical and the vertical edges of the door start or end on the bottom edge of the wall then
model = Sketchup.active_model ents = model.active_entities doors=[] ents.grep(Sketchup;;Face).each{|f| next unless f.normal.z==0 #vertical faces only top=f.bounds.max.z;btm=f.bounds.min.z f.edges.each{|e| next unless e.line[1].z.abs==1 #vertical edges only next unless e.bounds.max.z<top&&e.bounds.min.z==btm e.faces.each{|ff| next if ff==f || doors.include?(ff) UI.messagebox("Face; #{f.material.display_name} contains the Door #{ff.material.display_name} ") doors<<ff } } }
-
thnx for your answer.
there is a cases where a model can contain 2 windows linked to a door like the model below, but it doesn't appear using your code
-
@maryamr said:
thnx for your answer.
there is a cases where a model can contain 2 windows linked to a door like the model below, but it doesn't appear using your code
Seems rather odd to have windows connected to a door but then I'm no architect. It finds the door but it also thinks the door is a wall and the wall is a door because it has an edge that fits the door criteria, vertical and shorter than the adjoining face.
ps. Files posted should be version 8 so that, the unfortunate ones like myself who don't have the latest Sketchup version, can view the model.
Advertisement