@morisdov said:
@jim said:
Please add your own "Do and Don't" recommendations for writing SketchUp Ruby code.
DO wrap your plugin in a module (namespace) to avoid clashes.
DON'T use another person's registry keys, namespaces, or attribute_dictionaries.
The problem is you dont know who might have used what "name" , there are far too many other people out there for one to research their obvious common sence choices of keywords.
NO .. it's actually easy. If you stay in YOUR namespace, you can have your Plugin module(s) be any name and they will not clash.
Then.. use the namespace nesting to construct a unique registry key:
module Author
module Widget
# Construct a registry key to save the plugin options under;
#
@@opt_key = "Plugin_#{Module.nesting[0].name.gsub(/(;+)/,"_")}"
# Remove whitespace and non-word chars (just in case.)
@@opt_key = @@opt_key.gsub(/\s+/,"_").gsub(/\W+/,"")
# the key will be; "Plugin_Author_Widget"
end
end
Then you can use the registry key also as a prefix for any AttributeDictionary objects that this plugin uses:
module Author;;Widget
@@dictFlags = "#{@@opt_key}_Flags"
# create the dictionary
@dict = ent1.attribute_dictionary( @@dictFlags , true )
# the dictionary will be; "Plugin_Author_Widget_Flags"
end #module
Obviously,.. you replace the word "Author" with your own namespace identifier, and choose the name of your own plugin sub-modules, and their dictionary names.