Save and recall parameters of an object created with ruby
-
I'm writing an extension to create a wall in a simular way as the profile builder plugin. Before you draw the wall you have to adjust several parameters (height, width, ...). But when the wall is drawn I want the possibility to modify these parameters. How can I save those parameters to the wall object en how can I recall them when I want to modify the object?
-
Use an AttributeDictionary attached to the wall Component.
You can attach the dictionary to either the ComponentInstance or the ComponentDefinition (or both) depending on your needs. AttributeDictionaries can be attached to any SketchUp Entity or the Model for that matter. AttributeDictionaries are saved with the model on disc.
You use them similar to a Ruby Hash object, but they store the key/values to a SketchUp Entity. Use the
#set_attribute
and#get_attribute
methods of Entity objects. -
You should have a look at the SketchUp Team's Shapes and Window Maker example extensions. They (and a few others) use a library class called
Parametric
that handles creating a inputbox of parameters and saves them into an attribute dictionary attached to the (group or component) object.Why reinvent the wheel?
Advertisement