Problem with DC and attriubuires

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 (114.0 KB)

(1) Use Aerilius’ extension to examine attribute dictionaries:

(2) Try to always use:

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:
nazwa  = entity.get_attribute( "dynamic_attributes", "a_nazwa" )
f_szer = entity.get_attribute( "dynamic_attributes", "f_szer" )
puts nazwa.inspect
puts f_szer.inspect

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

1 Like

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

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.

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

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 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!

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

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.

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.

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.

<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.