Get the Name attribute ( error )
-
Explain where the error is?
I create a component (a simple cube)
And set attribute Name = test
Save the file as test.skp and close Sketchup.
Open the Sketchup file test.skp and enter in the Ruby Console code :model = Sketchup.active_model entity = model.selection[0] puts entity.get_attribute("dynamic_attributes","name","").to_s
get the name of the component test. (image1)
So far everything is fine.
Next, I save a component from the context menu "Save As"
Open a new file and load component cub from the menu Components
Again enter in the Ruby Console the same code
And get nothing. (image2)
Why when loading a component of their menu Components
code does not work ?
however , the code :Sketchup.active_model.selection[0].definition.attribute_dictionary('dynamic_attributes').each_pair { |k,v| puts k + '; ' + v.to_s }
correctly displays the name attribute of the component (among other attributes)
In the General case I need the code displays the name attribute of the component. -
I believe you are getting confused about the difference between a Component definition and instance. The dynamic_attributes dictionary is associated with an instance, not the definition. That's so that individual instances of the dynamic component can vary from one another according to these attributes. When you create a new instance from the Components window, it does not "inherit" dynamic_attributes assigned to other instances.
-
The thing is that when downloading from the Components window real component I can get the values of any attribute (and there are about 20) except for the value of the Name attribute.
Advertisement