How to apply attributes through code? and how do they work?
-
Things [each called an
Entity
] that are 'visible' in a model are typically geometry [lines, faces etc], and groups and components [what is commonly called a component is actually a 'component-instance']. These groups and instances contain geometry - they can also contain sub-groups and other instances. This is a simplified picture since there's also Images, Text, Dimensions etc etc but lets keep it simple !
Within the model's 'database' there are other things you can't see but that you can use - inside 'collections' called Materials, Layers, Styles and ComponentDefinitions. Each of these will have entries like Material, Layer, Style and ComponentDefinition.So far so good ?
When you look at the Components in the Browser you are looking into the model's database and seeing the Component-definitions available for use.
When you select [highlight] something in a model you can get its 'class' [typename etc] so with the initial examples above you have Sketchup::Edge, Sketchup::Face, Sketchup::Group and Sketchup::ComponentInstance.
Let's assume you have somehow set a variable
instance=ss[i]
which is aSketchup::ComponentInstance
.
You can find its definition thusdefinition=instance.definition
Now you can find an
instance.definition
but conversely you can find adefinition.instances
[i.e. all of that definition's instances]
Any particular definition's instance doesn't contain anything at all - it is a marker for the definition itself, soinstance.definition.entities
gives you a list of entities inside the definition that that instance is using...
You can even 'swap' an instance's definition for another one:instance.definition=another_definition
...
Advertisement