Get dynamic component attribute from SUGroup

Hi SketchUp C++ SDK experts,

I am using C++ SDK to query the dynamic attribute of Sketchup Instance and Group.
I can get the dynamic attribute from SUComponentInstanceRef by calling SUComponentInstanceCreateDCInfo.

However, I cannot figure out how to query the dynamic attribute from SUGroupRef.
What I tried:

  1. Cast SUGroupRef to SUComponentInstanceRef by SUGroupToComponentInstance
  2. Then call SUComponentInstanceCreateDCInfo on the result instance of step #1

I cannot get a valid SUDynamicComponentInfoRef for the SUComponentInstanceRef cast from SUGroupRef.

Am I doing the right way to query dynamic attribute for SUGroupRef?

Thank you,

What happens? Do you get error values?

Exactly what attributes are you looking for?

Thank for the reply.
If you go to the menu “Window”->“Component Attributes” for the selected group, you are able to add some attribute like the following snapshot shows.

To query the component attributes, I use the code snippet below.

            SUDynamicComponentInfoRef compInfo = SU_INVALID;
            SUComponentInstanceRef testInst = SUGroupToComponentInstance(group);
            auto result = SUComponentInstanceCreateDCInfo(testInst, &compInfo);
             if (!SUIsInvalid(compInfo) && result == 0)

The result of SUComponentInstanceCreateDCInfo is SU_ERROR_NO_DATA.
A simple model is attached about the group dynamic attribute.
cube.skp (123.7 KB)

Problem: dynamic groups cannot exist (as working) all alone.
They must (if a group) be a child of a dynamic component.

Also, the default dc attributes are attached to the component definition.
Any changes that an instance needs are overridden in a DC dictionary attached to the component instance.
But, … dc attributes for groups are always attached to the group instance (not the group’s definition.)

P.S. - In case you did not know, groups are a special subtype of component instance (whose definition is hidden from the “In Model” definitions collection in the GUI’s “Components” panel.) This is why there are type casting functions in the C API.

Do you have Aerilius’ Attributte Inspector extension installed ? It is must if you wish to poke into Dynamic Components development.

What do you mean about “dynamic groups cannot exist (as working) all alone”?
Do you mean I should create a component definition which includes the group?

I did not install “Attribute Inspector”. I just install one and play a while. It looks much more powerful than “Dynamic Components” extension.


BTW, the group in the “cube.skp” has only the following DC attributes in the “dynamic_attributes” dictionary.


You may not know, but the Dynamic Components dictionaries are not in any way different from the dictionaries that any other extension author creates, except that they are an “native” extension that is included with SketchUp.

You can access the "dynamic_attributes" dictionaries using the plain class functions …

An AttributeDictionary can be attached to ANY Entity subclass object. You’d upcast the subclass object ref to an Entity:

SUEntityRef entity_ref = SUGroupToEntity(group_ref);
SUAttributeDictionaryRef dict_ref = SU_INVALID;
res = SUEntityGetAttributeDictionary(entity_ref, "dynamic_attributes", &dict_ref);
    // dict_ref will be valid
    SUTypedValueRef val_x = SU_INVALID;
    vc_res = SUTypedValueCreate(&val_x);
    if (vc_res == SU_ERROR_NONE) {
        SUAttributeDictionaryGetValue(dict_ref, "x", &val_x);
        SUTypedValueType tvt;
        SUTypedValueGetType(val_x, &tvt);
        if (tvt == SUTypedValueType_Float || tvt == SUTypedValueType_Double ) {
            // Do something with the X value ...

A good Attribute Inspector extension can read and display any attribute dictionary from any extension, attached to any entity objects. The model itself, any of it’s collections, it’s definitions, or drawing entities.

However the are only reader / editors. They don’t make components dynamic. Only the native DC extension does this (using attribute dictionaries named "dynamic_attributes".)

1 Like

Thank you introducing SUAttributeDictionaryRef .
I will give it a try.
What I need to do is trying to get such attributes from the customer model.
In case the web application downgrade tool makes some attributes lost. I attached a 2018 version skp file.
What I see in the “Attribute Inspector” is a little bit different from your snapshot.
cube2018.skp (122.8 KB)
Those attributes are manually created in SketchUp 2019 Application UI with “Window”->“Component Attributes”.

Okay, I see the same attributes in the new download of the above post.

Okay BUT … SketchUp does not formally have “Dynamic Groups”. It has Dynamic Components.

So the topmost “parent” that is the entity in the model needs to be a component instance.
When you create the DC attributes on a component, the dialog and code will create “dynamic_attributes” dictionaries on both the definition and the instance, as necessary.
You’ll notice that the instances have much fewer attributes. Usually the minimum needed, and any whose values are unique to that instance. The definition’s DC dictionary will have all the attributes defining the UI labels, names, etc. that ALL instances will share.

The DC definition can have either child components or groups in it’s entities collection.

However, again, groups are special in that all DC attributes are written into a DC dictionary attached to the group instance (instead of it’s definition.)

Just remember to check the instance for the DC attribute you want first, and if it doesn’t exist (or the entity doesn’t have a “dynamic_attributes” dictionary,) … then always check the instance’s definition second.

I’d be worth your while to write up a little function that does just that, specially for DC attribute getting.

Very appreciated for the detailed explanation. They help me a lot. Thank you!

1 Like