How I get x,y,z values of components selected with mouse on computer?

Hi,
How i get x,y,z values of components selected with mouse computer, i wanna select components and get boundingbox information. Someone to help me? Using ruby API

You will need to write a class that implements methods from the Tool protocol (Tool is not a class, it just defines a suite of event handling methods an object can implement to be treated as a Tool by the GUI). In the class’s onLButtonDown callback, use a PickHelper to identify the ComponentInstance where the user clicked. Then you can use its bounds method to get the BoundingBox of the ComponentInstance.

If you wish a more command-like implementation based upon a preselection then,
within your extension submodule …

    def get_first_selected_instance
      model  = Sketchup.active_model
      selset = model.selection
      selset.grep(Sketchup::ComponentInstance).first
    end

    def get_position(inst)
      return ::ORIGIN unless inst
      inst.transformation.origin
    end

    def get_size(inst)
      return 0.to_l,0.to_l,0.to_l unless inst
      bb = inst.bounds
      bb.width, bb.height, bb.depth
    end

    inst = get_first_selected_instance()
    w, h, d = get_size(inst)
    x, y, z = get_position(inst).to_a
2 Likes