sketchucation logo sketchucation
    • Login
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Intersect two Component Instances

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 3 Posters 190 Views 3 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.
    • C Offline
      chochmah
      last edited by

      Hi Forum,
      I'm going crazy trying to intersect two component instances.

      I want to intersect a instance of the component Model and a instance of the component Plane and store the intersecting edges in intersection_edges in the Plane Component. I fail miserably probably because I don't really understand how the transformations work on instances. Any Help would be really great, I already spend more than 2 hours trying to get this to work.

      entities.each do |s|
       if s.definition.name=="Model"
        $model_tr = s.transformation
        $entities_model=s.definition.entities
       end
       if s.definition.name=="Plane"
        $plane_tr = s.transformation
        $entities_plane=s.definition.entities
       end
      end
      
      intersection_edges = $entities_plane.intersect_with(false,$model_tr.inverse ,$entities_plane,$plane_tr,false,$entities_model.collect)
      

      Thank you very much!

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        First off please don't use $ variables - one day they'll clash with other's code and cause disasters... use @ ones if your code spans 'def' methods...
        Also calling your component/instance 'model' is just confusing as that's normally used for 'the model' itself ! And 'plane' refers to something that a face has... ๐Ÿ˜’
        Make references to the two 'containers' instead of their entities !
        Say @xmodel and @xplane - we can deal with the entities later...

        Then try...
        intersection_edges = Sketchup.active_model.active_entities.intersect_with(true, @xplane.transformation.inverse , @xplane.definition.entities, @xplane.transformation.inverse , true, [@xmodel, @xplane])
        Note that 'intersection_edge's might also include new faces etc...
        This is untested ๐Ÿ˜ฎ - the principle is that you intersect the objects where they are and put the results into the desired container...
        Try messing around with the .inverse methods if the intersection id not where it's required...

        TIG

        1 Reply Last reply Reply Quote 0
        • C Offline
          chochmah
          last edited by

          @tig said:

          First off please don't use $ variables - one day they'll clash with other's code and cause disasters... use @ ones if your code spans 'def' methods...
          Also calling your component/instance 'model' is just confusing as that's normally used for 'the model' itself ! And 'plane' refers to something that a face has... ๐Ÿ˜’
          Make references to the two 'containers' instead of their entities !
          Say @xmodel and @xplane - we can deal with the entities later...
          Try messing around with the .inverse methods if the intersection id not where it's required...

          Thanks for the quick reply.
          I replaces the global variables and renamed the instances.

          model = Sketchup.active_model
          entities = model.entities
          
          instance_body=0
          instance_bulkhead=0
          
          entities.each do |s|
           if s.definition.name=="Model"
            instance_body=s;
           end
           if s.definition.name=="BPC"
            instance_bulkhead=s
           end
          end
          
          intersection_edges = Sketchup.active_model.active_entities.intersect_with(true, instance_bulkhead.transformation.inverse , instance_bulkhead.definition.entities, instance_bulkhead.transformation.inverse , true, [instance_body, instance_bulkhead])
          
          

          I tried every possible combination of inverse and non-inverse but there's always strange stuff happening. It does only work if both instances are not transformed at all so I guess it must have something to do with the transforms.

          Thank you very much

          http://666kb.com/i/c6z16r4fzyihtjhbr.jpg

          The lines are the intersection_edges

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            It's quite possible to get this to work... unfortunately I don't have a spare moment to look at it right now in any detail... have you tried permutations of all .transformation/.transformation.inverse to see what happens... This MIGHT work - assuming there are only 2 active entities !! Perhaps dump the 'inverse' = untested...

            
                model = Sketchup.active_model
                entities = model.active_entities
                instance_body=nil
                instance_bulkhead=nil
                entities.each do |s|
                 if s.definition.name=="Model"
                  instance_body=s
                 elsif s.definition.name=="BPC"
                  instance_bulkhead=s
                 end
                end
                return unless instance_body && instance_bulkhead
                tr=Geom;;Transformation.new()
                intersection_edges = entities.intersect_with(true, tr, instance_bulkhead.definition.entities, instance_bulkhead.transformation.inverse , true, [instance_body, instance_bulkhead])
            
            

            ???

            TIG

            1 Reply Last reply Reply Quote 0
            • C Offline
              chochmah
              last edited by

              Thank you! This works indeed. I just had to remove the one ".inverse".

                  intersection_edges = entities.intersect_with(true, tr, instance_bulkhead.definition.entities, instance_bulkhead.transformation, true, [instance_body, instance_bulkhead])
              
              

              The one remaining problem is now that there are usually more than two entities and this intersects all of them with the instance_body including the instance_body itself. Do you have a quick tip how to restrict the intersect to the two objects instance_body and instance_bulkhead?

              Thank you very much for your help, it's much appreciated

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

                Here is another shot at it for you to try

                model = Sketchup.active_model
                entities = model.entities
                model_component=nil;plane_component=nil
                cmps=entities.find_all{|c| c.class==Sketchup;;ComponentInstance}
                cmps.each{|c| (model_component=c;break) if c.name=="Model"}
                cmps.each{|c| (plane_component=c;break) if c.name=="Plane"}
                if model_component and plane_component
                 intersection_edges=plane_component.definition.entities.add_group;intersection_edges.name="Intersection_Edges"
                 plane_component.definition.entities.intersect_with(true,plane_component.transformation,intersection_edges.entities,intersection_edges.transformation,true,model_component)
                 intersection_edges.transform! plane_component.transformation.inverse
                else
                 UI.messagebox "Both components not found"
                end
                
                

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

                http://sdmitch.blogspot.com/

                1 Reply Last reply Reply Quote 0
                • C Offline
                  chochmah
                  last edited by

                  Thank you. That solved the last Problem with the intersect.

                  you guys have been very helpful@TIG,sdmitch Thanks a thousand

                  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