Find a face in another layer and group

Dear Friends,
In following codes, I made 2 boxes in 2 group and 2 layer. box2 is hide and face2 make a hole in box1.
I wish to check if another face in another group and layer is connected to face2 or not and if yes, make a hole in other group also (Box2 in this example). Can you help me for it?


require 'sketchup.rb'
module MajidMahmoudi
  module BoxTest
    class MajBox
      def init()
        @lay = Sketchup.active_model.layers 
        @st = 0
      end  
      def activate
        init()
        Sketchup.active_model.active_layer =  @lay.add('Layer1')
        # Box1
        pt1 = [-5, 0, 0]; pt2 = [5, 0, 0]; pt3 = [5, 10, 0]; pt4 = [-5, 10, 0]
        grp1 = Sketchup.active_model.active_entities.add_group
        face1 = grp1.entities.add_face pt1, pt2, pt3, pt4   
        face1.pushpull -10
        # Box2
        Sketchup.active_model.active_layer =  @lay.add('Layer2')
        Sketchup.active_model.active_layer = "Layer2"
        pt1 = [-5, 0, 0]; pt2 = [5, 0, 0]; pt3 = [5, -10, 0]; pt4 = [-5, -10, 0];
        grp2 = Sketchup.active_model.active_entities.add_group
        face1 = grp2.entities.add_face pt1, pt2, pt3, pt4
        face1.pushpull -10 
        @lay = Sketchup.active_model.active_layer
        @lay.visible= false
        Sketchup.active_model.active_layer = "layer1"
        ent = grp1.entities
        pt1 = [-3, 0, 2]
        pt2 = [3, 0, 2]
        pt3 = [3, 0, 8]
        pt4 = [-3, 0, 8]
        face2 = ent.add_face [pt1, pt2, pt3, pt4]
        face2.pushpull -10
        
        #Code Here
              
        Sketchup.active_model.active_layer = "Untagged"        
      end # activate
      def deactivate(view)
        view.invalidate
        Sketchup.status_text = ""
      end

      def suspend(view)
        view.invalidate
        Sketchup.status_text = ""
      end

      def resume(view)
        view.invalidate
        Sketchup.status_text = ""
      end
    end # class MajBox
#    unless file_loaded?(__FILE__)
      UI.menu("Plugins").add_item("MajBox") {
      Sketchup.active_model.select_tool(MajBox.new)
      }
#      file_loaded(__FILE__)
#    end
  end # BoxTest
end # MajidMahmoudi

Each method needs to be separated by an empty line.

1 Like

Layer / Tags in SketchUp are not geometric collections. They are just a property that can be assigned for display behavior regardless of the entity position in the model hierarchy.

First of all … group and component entities contexts separate geometry, so they cannot be “connected”.

Re: finding a face in another group …

So where is your attempt at coding this ?

You need to start trying to solve your own coding challenges.

At the very least, … please first search the Ruby API category for past similar questions and topics. This (how to find a face) has been asked before several times.

2 Likes

it is big advantage for me to know there is no especial code for this purpose. I just send my codes to show my problem clearly. if you let me ask another question. we have a point and a face, do you know any code that can show point is on face or not?

You also need to attempt to find methods yourself in the API documentation
We shouldn’t have to look up method(s) for you. The only way that you will learn to know your own way around the documentation is to search through it. …

1 Like