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

    Input_point: which component?

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 3 Posters 517 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.
    • daikuD Offline
      daiku
      last edited by

      I'm writing a new tool, and I want to modify the component that the user has chosen. I can get the vertex from an input point, but how can I figure out which component that vertex is part of? CB.

      Clark Bremer
      http://www.northernlightstimberframing.com

      1 Reply Last reply Reply Quote 0
      • T Offline
        todd burch
        last edited by

        Climb the tree. It has a parent, and it has also has a parent, and so on and so on.

        1 Reply Last reply Reply Quote 0
        • daikuD Offline
          daiku
          last edited by

          Thanks Todd. That's what I've been trying to do. The input point will tell me the depth, but no matter how deep, I always seem to be in a shallow tree, which is component_definition, followed by a definition_list, followed by the model.

          
          print("\n input point depth;" + @ip1.depth.to_s + "\n")
          print("vertex; " + vtx.position.to_s + "\n")
          p = vtx
          until p == Sketchup.active_model
          	p = p.parent
          	print("parent; " + p.to_s + "\n")
          end	
          

          Yields:

          @unknownuser said:

          input point depth:2
          vertex: (0", 14.396265", 8")
          parent: #Sketchup::ComponentDefinition:0xafca550
          parent: #Sketchup::DefinitionList:0xafd7540
          parent: #Sketchup::Model:0x4ddaa70

          input point depth:4
          vertex: (0", 0", 2.75")
          parent: #Sketchup::ComponentDefinition:0xafb90d8
          parent: #Sketchup::DefinitionList:0xafd7540
          parent: #Sketchup::Model:0x4ddaa70

          Clark Bremer
          http://www.northernlightstimberframing.com

          1 Reply Last reply Reply Quote 0
          • T Offline
            todd burch
            last edited by

            Hey Clark.

            OK, you mean which component instance. If so, that's a big hole in the OO model we have. I seem to remember trying to do this some time ago, and I don't remember if I figured it out or not. I know this has been discussed before. Sorry I don't have an immediate answer.

            1 Reply Last reply Reply Quote 0
            • daikuD Offline
              daiku
              last edited by

              Well, even igonoring the instances, shouldn't one definition be nested within the next? These objects I'm clicking on are deeply nested sub-components. CB

              Clark Bremer
              http://www.northernlightstimberframing.com

              1 Reply Last reply Reply Quote 0
              • T Offline
                todd burch
                last edited by

                When you do a pick, you can get get a picklist (name?) of all the entities that could have satisfied the pick, but maybe were deeper in the array of choices. So, perhaps the closest (read, "most outer") entity is being returned for the simple pick. Look deeper in the picklist (or whatever it's called) and perhaps pick the deepest entity - maybe that's the one you want.

                1 Reply Last reply Reply Quote 0
                • fredo6F Offline
                  fredo6
                  last edited by

                  Clark,

                  You can take inspiration from the following code

                  
                  def which_component_picked(view, x, y, ip=nil)
                  	#Finding an edge or a face picked
                  	ip = Sketchup;;InputPoint.new unless ip
                  	ip.pick view, x, y	
                  	ee = [ip.edge, ip.face].find { |e| e }
                  	return nil unless ee && ee.parent.class == Sketchup;;ComponentDefinition
                  		
                  	#Finding the instances in the pick list
                  	instances = ee.parent.instances	
                  	ph = view.pick_helper
                  	ph.do_pick x, y
                  	comp = (ph.count > 0) ? ph.path_at(0).find { |e| instances.include?(e) } ; nil
                  end
                  
                  

                  First you check if you have picked a vertex, an edge or a face. If so, you check if the parent is a ComponentDefinition.
                  Then you use a HelpPicker to check the full path of picked entities, and retrieve the first instance of the definition within this path.

                  Fredo

                  1 Reply Last reply Reply Quote 0
                  • daikuD Offline
                    daiku
                    last edited by

                    This is exactly the info I needed. Thanks guys! CB.

                    Clark Bremer
                    http://www.northernlightstimberframing.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