Storing File Specific Attributes
-
I'm fairly well versed in storing attributes for various entities (groups, components etc...) but I would now like to store some attributes that are "file" or "model" specific. These are some global settings that will apply to the model that is opened up in SketchUp. I am wondering if there is a preferred way of doing this and any pitfalls to look out for.
-
Assuming that...
model = Sketchup.active_model
To set a key/value...
model.set_attribute("Some_Dict_Name", "Some_Key", value)
To get a key/value...
model.get_attribute("Some_Dict_Name", "Some_Key", default_value)
If you don't pass adefault_value
and its"Some_Key"
has not been set you get back 'nil
'.
The 'value
' can be one of several types...
boolean nil/false/true
integer 1, 0, -1
float 1.0, 0.0, -1.0
string "cat", "or dog"
array [true, 1, 2.345, "doh", [1,2,3]] (i.e. it can include any of the other 'types') -
"Some_Dict_Name"
needs to be"Medeek_SomePluginName"
at a minimum, and can be expanded even more, like:"Medeek_SomePluginName_Purpose"
if "SomePluginName" will have more than one dictionary, each used for different purposes.Or you can nest dictionaries inside another dictionary. So you can have one toplevel company dictionary for all your plugins, called
"Medeek"
(or whatever) and create child dictionaries for whatever plugins that need them. Those child dictionaries could have grandchild dictionaries.But it is most important to know that you must separate your dictionaries from those of other authors. (It is up to you how to separate your various plugin dictionaries.)
Advertisement