Rich,
You can set attributes and their formulas using the API, but it's not a documented process, unfortunately. Here's a kick start.
All of the attributes are stored inside an AttributeDictionary called dynamic_attributes, as you discovered. In addition to the attribute's value, there are a series of "meta attributes" that describe properties of the DC attribute. These start with underscores, and they must be defined to work properly with the DC plugin. (They attribute keys are all lowercase.)
Let's say you have an attribute called "FavoriteColor" that you manually create in the Component Attributes window. These are the attributes that the DC plugin would create if you made it end user editable (and therefore, these are the attributes your plugin would need to make to do it in Ruby code...)
favoritecolor = "Red" # The raw value of the att.
_favoritecolor_formula = "" # The formula, if set.
_favoritecolor_label = "FavoriteColor" # The "cased" name of the att
_favoritecolor_access = "TEXTBOX"
access = "NONE" if consumers can't see or edit this attribute
= "VIEW" if consumers can see this attribute
= "TEXTBOX" if consumer can enter a value for this attribute
= "LIST" if consumers can select a value from a list
_favoritecolor_options = "Pink=pink&Red=255,0,0&Blue=blue" # url encoded list
_favoritecolor_units = "STRING"
_favoritecolor_formlabel = "Favorite Color"
I wish I had complete documentation for all of this to share, but the best I can offer at the moment is a willingness to help. The best thing to do would be to use an attribute reading script to watch what attributes get set when you do things in the DC UI.
Here's a code snippet that demonstrates creating some new attributes on the Sang component...
UI.menu("Plugins").add_item('Make Sang Red') {
# Assumes that sang is the 1st entity in model.
sang = Sketchup.active_model.entities[0]
sang_def = sang.definition
# Override sang's shirt color to red. ("material"
# is a special attribute that requires
# you to set a formula to "take control"
# over the default material the user has painted.)
sang_def.set_attribute 'dynamic_attributes',
'material', 'red'
sang_def.set_attribute 'dynamic_attributes',
'_material_formula', '"red"'
# Add a new configurable option to Sang.
# (Any attribute that starts with an underscore
# is a "meta attribute" that describes behavior.)
sang_def.set_attribute 'dynamic_attributes',
'weight', '145'
sang_def.set_attribute 'dynamic_attributes',
'_weight_label', 'weight'
sang_def.set_attribute 'dynamic_attributes',
'_weight_formlabel', 'My Weight'
sang_def.set_attribute 'dynamic_attributes',
'_weight_units', 'STRING'
sang_def.set_attribute 'dynamic_attributes',
'_weight_access', 'TEXTBOX'
# Change the description that shows
# up in the configure box with a custom
# formula.
sang_def.set_attribute 'dynamic_attributes',
'_description_formula',
'"Sang is now red and weighs " & weight'
# There is a global handle into the plugin that
# allows you to make the same calls that the
# plugin does, like so...
dcs = $dc_observers.get_latest_class
dcs.redraw_with_undo(sang)
}