# "Parent" Reference

**URL:** <https://forums.sketchup.com/t/parent-reference/4862>\
**Category:** Dynamic Components\
**Created:** [December 13, 2014, 5:57pm UTC](https://forums.sketchup.com/t/parent-reference/4862 "2014-12-13T17:57:27Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![jim\_foltz](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jim_foltz/32/74787_2.png) [@jim\_foltz](https://forums.sketchup.com/u/jim_foltz)\
**Post date:** [December 13, 2014, 5:57pm UTC](https://forums.sketchup.com/t/parent-reference/4862/1 "2014-12-13T17:57:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Anssi](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/anssi/32/105_2.png) [@Anssi](https://forums.sketchup.com/u/Anssi)\
**Post date:** [December 13, 2014, 6:57pm UTC](https://forums.sketchup.com/t/parent-reference/4862/2 "2014-12-13T18:57:20Z")

</div>

This was new to me. But what happens if you name the component or one of its subcomponents “Parent”?

Anssi

---

<div class="post-metadata">

**Author:** ![jim\_foltz](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jim_foltz/32/74787_2.png) [@jim\_foltz](https://forums.sketchup.com/u/jim_foltz)\
**Post date:** [December 13, 2014, 6:59pm UTC](https://forums.sketchup.com/t/parent-reference/4862/3 "2014-12-13T18:59:32Z")

</div>

Excellent question. It seems SketchUp has thought of it.

---

<div class="post-metadata">

**Author:** ![Jeff](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jeff/32/1163_2.png) [@Jeff](https://forums.sketchup.com/u/Jeff)\
**Post date:** [December 13, 2014, 7:05pm UTC](https://forums.sketchup.com/t/parent-reference/4862/4 "2014-12-13T19:05:51Z")

</div>

I’ve done it that way on quite a few occasions. are you sure it’s not documented? (ie- I learned it, I didn’t just discover it on my own)

otherwise, I suppose I could of just picked it up from an individual along the way… maybe it was you 😉

---

<div class="post-metadata">

**Author:** ![Anssi](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/anssi/32/105_2.png) [@Anssi](https://forums.sketchup.com/u/Anssi)\
**Post date:** [December 13, 2014, 11:32pm UTC](https://forums.sketchup.com/t/parent-reference/4862/5 "2014-12-13T23:32:39Z")

</div>

> [@jim\_foltz](#):
>
> It seems SketchUp has thought of it.

No error messages for me, but in the Attributes dialog the Parent component becomes listed as “ParentEntity”

Anssi

---

<div class="post-metadata">

**Author:** ![jim\_foltz](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jim_foltz/32/74787_2.png) [@jim\_foltz](https://forums.sketchup.com/u/jim_foltz)\
**Post date:** [December 13, 2014, 11:52pm UTC](https://forums.sketchup.com/t/parent-reference/4862/6 "2014-12-13T23:52:47Z")

</div>

Right. Double-click the name to try renaming it to “Parent”. You should get the error message.

---

<div class="post-metadata">

**Author:** ![Cotty](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/cotty/32/251290_2.png) [@Cotty](https://forums.sketchup.com/u/Cotty)\
**Post date:** [December 14, 2014, 9:09am UTC](https://forums.sketchup.com/t/parent-reference/4862/7 "2014-12-14T09:09:14Z")

</div>

I’ve learned this from Eric in his great Basecamp video:

[![](https://global.discourse-cdn.com/sketchup/original/3X/f/d/fd12327166db62674eb464b7c41c9c3ce41f361d.jpeg "3D Basecamp 2014: Dynamic Components, Greatest Hits, Vol. 1, Eric Schimelpfenig") ](https://www.youtube.com/watch?v=uy1UadpBJeA)

---

<div class="post-metadata">

**Author:** ![Kilizarov](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kilizarov](https://forums.sketchup.com/u/Kilizarov)\
**Post date:** [October 27, 2016, 4:55pm UTC](https://forums.sketchup.com/t/parent-reference/4862/8 "2016-10-27T16:55:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Anssi](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/anssi/32/105_2.png) [@Anssi](https://forums.sketchup.com/u/Anssi)\
**Post date:** [October 27, 2016, 5:04pm UTC](https://forums.sketchup.com/t/parent-reference/4862/9 "2016-10-27T17:04:55Z")

</div>

> [@Kilizarov](#):
>
> I wrote a formula “=Parent!Name”

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.

Anssi

---

<div class="post-metadata">

**Author:** ![Kilizarov](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kilizarov](https://forums.sketchup.com/u/Kilizarov)\
**Post date:** [October 27, 2016, 6:57pm UTC](https://forums.sketchup.com/t/parent-reference/4862/10 "2016-10-27T18:57:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TIG](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tig/32/198_2.png) [@TIG](https://forums.sketchup.com/u/TIG)\
**Post date:** [October 27, 2016, 7:16pm UTC](https://forums.sketchup.com/t/parent-reference/4862/11 "2016-10-27T19:16:03Z")

</div>

\_name ?

---

<div class="post-metadata">

**Author:** ![Kilizarov](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kilizarov](https://forums.sketchup.com/u/Kilizarov)\
**Post date:** [October 27, 2016, 7:31pm UTC](https://forums.sketchup.com/t/parent-reference/4862/12 "2016-10-27T19:31:37Z")

</div>

Wow, Thank you! This works!!

---

<div class="post-metadata">

**Author:** ![Kilizarov](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kilizarov](https://forums.sketchup.com/u/Kilizarov)\
**Post date:** [October 27, 2016, 7:44pm UTC](https://forums.sketchup.com/t/parent-reference/4862/13 "2016-10-27T19:44:12Z")

</div>

Still it works from time to time, thats weird.

---

<div class="post-metadata">

**Author:** ![TIG](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tig/32/198_2.png) [@TIG](https://forums.sketchup.com/u/TIG)\
**Post date:** [October 27, 2016, 8:10pm UTC](https://forums.sketchup.com/t/parent-reference/4862/14 "2016-10-27T20:10:22Z")

</div>

‘Built-in’ keys are usually prefixed by an `_`  
So the displayed  
`name`  
is actually  
'\_name`  
???  
Dump the selected DC instance’s keys/values using:

`Sketchup.active_model.selection[0].definition.attribute_dictionaries['dynamic_attributes'].each_pair{|k,v| puts"#{k} = #{v}"}`

This will return a list if it’s a DC…

---

<div class="post-metadata">

**Author:** ![MogensenCo](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@MogensenCo](https://forums.sketchup.com/u/MogensenCo)\
**Post date:** [October 28, 2016, 8:20pm UTC](https://forums.sketchup.com/t/parent-reference/4862/15 "2016-10-28T20:20:14Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Kilizarov](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kilizarov](https://forums.sketchup.com/u/Kilizarov)\
**Post date:** [October 28, 2016, 9:10pm UTC](https://forums.sketchup.com/t/parent-reference/4862/16 "2016-10-28T21:10:11Z")

</div>

Well, Looks like I’ll have to learn Ruby to make things work. I dont even understand where to put the code you gave.

---

<div class="post-metadata">

**Author:** ![TIG](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tig/32/198_2.png) [@TIG](https://forums.sketchup.com/u/TIG)\
**Post date:** [October 28, 2016, 9:29pm UTC](https://forums.sketchup.com/t/parent-reference/4862/17 "2016-10-28T21:29:30Z")

</div>

Select one DC component-instance.  
Open the Ruby Console.  
Edit\>Copy the one line of text I gave you:

` Sketchup.active_model.selection[0].definition.attribute_dictionaries['dynamic_attributes'].each_pair{|k,v| puts"#{k} = #{v}"}`

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…

It’s not so hard to do.
