How to get Parent Component Name in a Ruby Label Formula?

Hello everyone, I’m trying to add the parent component’s definition name to my labels using a Ruby formula, but I’m getting errors. My goal is to have a label that says “Name: [Parent Component Name]”. I have tried the following formulas without success: 1. “Nome: %{parent_definition_name}” (Error: “Forbidden const”) 2. “Nome: #{part.parent.definition.name}” (Error: “undefined local variable or method ‘part’”) 3. "Nome: " + parent_definition_name (Error: “undefined local variable or method ‘parent_definition_name’”) Could you please tell me what is the correct variable and syntax to achieve this? I have attached a screenshot of my last attempt. Thank you for your help!

As DC attributes are available, then add an attribute which reads the parents “_name”, if this differs, due changes made, can set using


onclick      set(“_name”,”you write the current DC name”)

“Name” would be the ideal attribute in the parts as can be shown via options

Ideally the parent should use the instance name, this takes a bit of ruby to automate in Sketchup

@boris.beaulant

is there another way?

Hello,

You can’t get parent’s definition name or any other parent attributes through formulas. You can only access to ancestors Instance names by using the @path variable.

@path variable is an array of ancestor instance names (if they are not empty).

So if parent instance have a name. just use @path.last (to get the last element of the array)

But this is an interesting need. Maybe the @path variable should hold instance objects instead of just names … :thinking: ?

1 Like