Continuing the discussion from Set up new entities to group or create a new entites list, because this post is on another topic than that thread:
No.
No.
Cutlist (and many other types of) plugins use custom Sketchup::AttributeDictionary
objects that they attach to any model entity.
Any Sketchup::Entity
subclass object within the model, can have multiple attribute dictionaries attached to it. They can be but do not need to be geometric (Sketchup::Drawingelement
subclass) objects. You can also attach attribute dictionaries to the model itself, or any of it’s collection class objects (like the Pages, the Entities, the Layers collections, etc.)
But the model is a shared space, so you need to prefix your dictionary name the same as you would for your author namespace module and plugin submodule, but with any scope operator (ie, ::
,) replaced with an underscore …
Example:
module YChen
module SectionPlugin
DICT_KEY ||= Module.nesting[0].name.gsub('::','_')
#=> "YChen_SectionPlugin"
extend self
# Gets (and creates if needed) this plugin's attribute dictionary for
# the argument entity object.
# @param entity [Sketchup::Entity] any API entity subclass object.
# @return false if argument cannot have attribute dictionaries.
# @return [Sketchup::AttributeDictionary] attached to argument entity.
def get_plugin_attr_dict(entity)
return false unless entity.respond_to?(:attribute_dictionary)
entity.attribute_dictionary(DICT_KEY,true)
end
# more methods and code ...
def add_data(entity,key,value)
dict = get_plugin_attr_dict(entity)
dict[key]= value
end
def get_data(entity,key,fallback=nil)
dict = get_plugin_attr_dict(entity)
value = dict[key]
return fallback if value.nil?
value
end
end # this plugin submodule
end # outer namespace module