sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Find to which face a door belong

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 684 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      MaryamR
      last edited by

      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.


      the model's image


      the model skp file

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        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
          }
         }
        }
        

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • M Offline
          MaryamR
          last edited by

          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


          Screenshot (26).png


          data extraction.skp

          1 Reply Last reply Reply Quote 0
          • sdmitchS Offline
            sdmitch
            last edited by

            @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.

            Nothing is worthless, it can always be used as a bad example.

            http://sdmitch.blogspot.com/

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement