How To Make Custom Dynamic Component Attribute

The same way that the DC extension does this, is the same way many extensions do it. And that is to save the setting in a custom attribute dictionary attached to the instance.

Dictionaries are accessible to any code, so just like the shared top level Ruby namespace, you should qualify your extension’s dictionaries with your author/company name and extension name as a prefix.
So for example say that your toplevel “company” namespace module was “JGinc” and your extension’s name was “VehicleWizard”, then your modules would be qualified as:

JGinc::VehicleWizard

Then, I always suggest qualifying your extension dictionaries with the same but replacing the :: scope operator with an underscore so that your dictionary would be named "JGinc_VehicleWizard".
If your extension needs different kinds of dictionaries for different kinds of “objects” you have the choice of either adding a suffux, like: "JGinc_VehicleWizard_Properties", "JGinc_VehicleWizard_Options", etc., or you can nest dictionaries within dictionaries (because dictionaries are a subclass of Sketchup::Entity, and all subclasses of this class can have a collection of dictionaries.)
So your “objects” can be given a custom “toplevel” dictionary named "JGinc_VehicleWizard", which could have sub-dictionaries named “Properties”, “Options”, etc.

Your choice. However, don’t expect that toplevel dictionaries with common names like “Properties” would not be used by more than one extension, that doesn’t know about the other, causing data clashes / corruption.

1 Like