How to know number of face parent component?

Hello,
I have some groups where their parent is a component and this component is repeated. Now I select a face in one of the groups in one of the components. How can I know the number of this component?

grp1 = face1.parent.instances[0]
comp = grp1.parent.instances[3]

I don’t know how to get #3?
Thank you in advance for your help.

The only way to know which of the instances the user has “drilled into”, is to get the active edit path:

It seems this method only works if we double click on a component to edit its geometry. I wish to click on a face and have the same information as active_path. Is it possible?

:bulb: The InputPoint #instance_path method retrieves the instance path for the picked point.

class TestTool
  def initialize()
    @ip = Sketchup::InputPoint.new
  end
  
  def onMouseMove(flags, x, y, view)
    @ip.pick(view, x, y)
    @in_path = @ip.face ? @ip.instance_path : nil
    if @in_path && @in_path.to_a.first.is_a?(Sketchup::ComponentInstance)
      @ttip = @in_path.to_a.first.name
    end
    view.invalidate
  end

  def draw(view)
    @ip.draw(view) if @ip.valid?
    view.draw_points( @ip.position, 25, 3, "green" ) if @ip.valid?
    view.tooltip = @ttip
    view.draw_text([10,10], @in_path.to_a.join("\n")) if @in_path
  end
end
Sketchup.active_model.select_tool(TestTool.new)

ipath

2 Likes

This indicates you are writing a Tool. The first post only said you had a selected face.
Please be more specific. @dezmo has given you the Tool answer.

1 Like

You are great. “@ip.instance_path.to_a” solve my problem.