# Problem with DC and attriubuires

**URL:** <https://forums.sketchup.com/t/problem-with-dc-and-attriubuires/23627>\
**Category:** Ruby API\
**Created:** [April 14, 2016, 4:57pm UTC](https://forums.sketchup.com/t/problem-with-dc-and-attriubuires/23627 "2016-04-14T16:57:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mamjankowski](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@mamjankowski](https://forums.sketchup.com/u/mamjankowski)\
**Post date:** [April 14, 2016, 4:57pm UTC](https://forums.sketchup.com/t/problem-with-dc-and-attriubuires/23627/1 "2016-04-14T16:57:30Z")

</div>

I have problem with getting value from DC (in attached files).  
I run code:  
mod = Sketchup.active\_model # Open model  
ent = mod.entities # All entities in model  
sel = mod.selection # Current selection  
ent.each { | entity |  
nazwa = entity.get\_attribute “dynamic\_attributes”, “a\_nazwa”  
f\_szer = entity.get\_attribute “dynamic\_attributes”, “f\_szer”  
UI.messagebox (nazwa)  
UI.messagebox (f\_szer)

```
entity.attribute_dictionaries.each {|aqq| UI.messagebox aqq
aqq.each { | key | UI.messagebox key }

```

}}

And I don’t see all attribiutes.

Do you have any idea what I doing wrong?

[S2S\_spf\_320\_G.skp](https://forums.sketchup.com/uploads/short-url/qMAmExMGqxfHomncscHSJCFwNUJ.skp) (114.0 KB)

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 14, 2016, 8:09pm UTC](https://forums.sketchup.com/t/problem-with-dc-and-attriubuires/23627/2 "2016-04-14T20:09:48Z")

</div>

**(1)** Use **Aerilius’** extension to examine attribute dictionaries:  
[http://extensions.sketchup.com/en/content/attribute-inspector](http://extensions.sketchup.com/en/content/attribute-inspector)

* * *

**(2)** Try to always use:

```ruby
ents = model.active_entities

```

* * *

**(3)** Do not use **`UI.messagebox`** for debugging. It itself can fail silently.

- Instead, open the Ruby console and use `puts()` statements:

```ruby
nazwa = entity.get_attribute( "dynamic_attributes", "a_nazwa" )
f_szer = entity.get_attribute( "dynamic_attributes", "f_szer" )
puts nazwa.inspect
puts f_szer.inspect

```

---

<div class="post-metadata">

**Author:** ![thomthom](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/thomthom/32/12606_2.png) [@thomthom](https://forums.sketchup.com/u/thomthom)\
**Post date:** [April 15, 2016, 1:13pm UTC](https://forums.sketchup.com/t/problem-with-dc-and-attriubuires/23627/3 "2016-04-15T13:13:17Z")

</div>

> [@mamjankowski](#):
>
> And I don’t see all attribiutes.

You have an instance selected, right? Most attributes are stored on the definition.

---

<div class="post-metadata">

**Author:** ![mamjankowski](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@mamjankowski](https://forums.sketchup.com/u/mamjankowski)\
**Post date:** [April 15, 2016, 2:00pm UTC](https://forums.sketchup.com/t/problem-with-dc-and-attriubuires/23627/4 "2016-04-15T14:00:11Z")

</div>

Ok,  
But if I change some values of attributes in instance they will be changed in definition?  
Is’n it a little strange?

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 15, 2016, 2:24pm UTC](https://forums.sketchup.com/t/problem-with-dc-and-attriubuires/23627/5 "2016-04-15T14:24:33Z")

</div>

> [@mamjankowski](#):
>
> But if I change some values of attributes in instance they will be changed in definition?

Not true.

If the instance **needs** different values, then these values will be stored in the dictionary attached to the instance.

If the instance does not need different values, then there **may not** be a “dynamic\_attributes” dictionary attached to the instance. All values will then be used per the dictionary attached to the definition.

Sometimes, when the user changes attributes on an instance, the DC extension will make a unique definition for that particular instance.

---

<div class="post-metadata">

**Author:** ![mamjankowski](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@mamjankowski](https://forums.sketchup.com/u/mamjankowski)\
**Post date:** [April 15, 2016, 2:28pm UTC](https://forums.sketchup.com/t/problem-with-dc-and-attriubuires/23627/6 "2016-04-15T14:28:50Z")

</div>

Exactly, I checked it. You’re right.  
Thank you both.

---

<div class="post-metadata">

**Author:** ![sjdorst](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/sjdorst/32/13212_2.png) [@sjdorst](https://forums.sketchup.com/u/sjdorst)\
**Post date:** [April 15, 2016, 3:19pm UTC](https://forums.sketchup.com/t/problem-with-dc-and-attriubuires/23627/7 "2016-04-15T15:19:34Z")

</div>

> [@DanRathbun](#):
>
> Sometimes, when the user changes attributes on an instance, the DC extension will make a unique definition for that particular instance.

I’d like to ask for a clarification: Under what circumstances does this happen? Can you have multiple DC instances that derive from the same DC definition that have the same dynamic attributes but different attribute **values**?

Say I have two instances of a DC in my model, both with an attribute “Foobar”. Using the dynamic attributes window (or the options window), I set “Foobar” to “Foo” in one instance and to “Bar” in the other. Can I do this?

Another question is: can I have multiple instances of a DC with different attributes defined (NOT attribute values)?

My interest here comes from my involvement with this conversation: [Three-option hidden components](http://forums.sketchup.com/t/three-option-hidden-components/23353/6) where I’m trying (slowly) to help @chrisjewett28 with his DC. At this point, I’ve deferred discussion with him on the problems he’s having with multiple instances, but it will likely come up again.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 15, 2016, 4:11pm UTC](https://forums.sketchup.com/t/problem-with-dc-and-attriubuires/23627/8 "2016-04-15T16:11:33Z")

</div>

First of all, it’s a SketchUp OEM extension and they should be answering these questions in their documentation. (ie, not really my job.)

> [@sjdorst](#):
>
> Under what circumstances does this happen?

Short answer: Whenever the extension code determines it needs to happen.

I guess most often if the DC has nested DCs that change with number of copies, like a fence component.

> [@sjdorst](#):
>
> Can you have multiple DC instances that derive from the same DC definition that have the same dynamic attributes but different attribute values?

I do not think so if the differing DC instances are nested within a group or component. Because then the uniqueness of the parent comes into play.

Yes, certainly simple changes like material and color attribute changes do not cause the unique-ifying of the definition.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 15, 2016, 4:18pm UTC](https://forums.sketchup.com/t/problem-with-dc-and-attriubuires/23627/9 "2016-04-15T16:18:37Z")

</div>

> [@sjdorst](#):
>
> Another question is: can I have multiple instances of a DC with different attributes defined (NOT attribute values)?

Not if they come from a definition. But later via an Ruby observer you could add any attributes you need, to any dictionary. So this includes the instance’s dictionary. But if such an attribute does not interact with other dynamic attributes, then it really belongs in a custom dictionary.

* * *

Exception: Unless, say, it’s just informational, and the user needs an easy way to change these attributes, and later they’ll be included in a report.

I can see not wanting to program a whole new interface just to add some text data to components, when the goal is to have them included in report generation.

---

<div class="post-metadata">

**Author:** ![sjdorst](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/sjdorst/32/13212_2.png) [@sjdorst](https://forums.sketchup.com/u/sjdorst)\
**Post date:** [April 15, 2016, 5:03pm UTC](https://forums.sketchup.com/t/problem-with-dc-and-attriubuires/23627/10 "2016-04-15T17:03:47Z")

</div>

> [@DanRathbun](#):
>
> First of all, it’s a SketchUp OEM extension and they should be answering these questions in their documentation

`<slaps self on forehead>` Duh! I was so focused on “Sometimes” that the context of the thread just didn’t penetrate my thick head! Thus my questions weren’t really applicable.
