It has become common when creating DC’s to reference attributes in a parent component by using the “Parent” keyword rather than the name of the parent Component. I have been recommending its use because it allows more flexibility in replacing sub-components of a DC.
This “trick” does not appear to be documented anywhere. Is it officially supported by SketchUp? Is using “Parent” a best practice? If so, it should be put in the DC documentation somewhere.
Well, I tried to use “Parent” for one thing and now i have a question to anybody who might know the answer.
I am trying to make an attribute formula, that would allow a component
to recieve a string data containing a name of parent component or group.
First thing I did is I wrote a formula “=Parent!Name” but that didn’t
work. I’ve tried several formulas, but still didn’t get a desired result.
Maybe you know just the right answer?
I cannot do tests right now, but your formula refers to a parameter called “Name” in the “parent”, so if the parameter is not defined, you should get an error message. I am not sure if there is a formula that will get the component definition or instance name and put it into a parameter.
Thank you for reply. Well, this works if I add an attribute “Name” to a parent group/component and type in some value, e.g. “A”. Then child component recieves “A” value through formula “=Parent!Name”.
Looks like my first question was incorrect.
The point is, I’m looking for a way to make child component automatically recieve definition value without need to add attribute “Name” to parent group/component.
the ‘parent!attributename’ operator is very useful - I use it a lot - it works like this in the formula:
=parent!lenx
Returns the value of the parent component/group attribute called ‘lenx’
=parent!mycustomattribute
Returns the value of the parents attribute called ‘mycustomattribute’
The attribute must exist on the parent, so ‘=parent!name’ will only work if the parent has an attribute called ‘name’
‘name’ is not the name of the definition/instance, but the name attribute of the dynamic component - which is a predefined attribute you can add to your dynamic component.
It can be used in formulas also like:
=IF(parent!lenx<100,0,100)
Edit>Paste the text into the Console + [enter].
That then runs and looks at the component’s definition and finds its DC attributes.
It then prints the key and value of each of those.
That way you can see that what you thought would be called ‘name’ is actually ‘_name,’ and so on…