Ruby api set a new dynamic attributes attributes and value but this windows can not display that value

sketchup-pro

#1

i create a component. like it

.
then i use ruby api like this:
model = Sketchup.active_model
selection = model.selection
en = selection[0]
en.set_attribute “dynamic_attributes”, “Vico01”, “123*12”
And then i open this window:
the value of Vico01 is display null and get this ERRORl:

why the dialog window can not display this value. how do for fix it.


#2

First of all I’d recommend to use a graphical tool to set the attributes, e.g. Aerilius’ Attribute Inspector. This makes it easier to see what you are doing, e.g. make sure names aren’t misspelled, and that the attribute type matches similar attributes.

However I’d also discourage building anything around Dynamic Components. Dynamic Components have no public documented API, and are not meant to be interacted with from other scrips. Any third party scripts that successfully interacts with DCs does it just by change, not because DC is designed to work that way, and any change in DCs could break it.


#3

Also the Dynamic Components Extension has its own “language” for expressions in attributes. That means it needs to parse and validate the value before it knows it is an expression that it can evaluate. This means two things:

  1. You cannot easily debug the issue if you don’t really see the current (possibly invalid) attribute value. Maybe Dynamic Components displays only values only after validation.
  2. You risk easily introducing errors by setting dynamic attributes through the backdoor because you bypass validation. (Therefore Dynamic Components should have (if it has not) a setter method API that applies validation).

Bear in mind that dynamic components are not a feature of the .skp file format, but an extension that only runs in this implementation of SketchUp (not in the Web version, not in third-party apps that implement an .skp reader (through the SDK) like Unity or Enscape). And dynamic components have not seen active development for a long time.