require 'sketchup.rb' $dictname="customdictionary" $model=Sketchup.active_model def add_attribute(name,value) $model.set_attribute $dictname, name, value end add_attribute("name", "model") #add_attribute( "tuut", 123); $dict=$model.attribute_dictionaries[$dictname] if 1 #add a context menu handler to add attributes to objects UI.add_context_menu_handler do |menu| if( Sketchup.active_model.selection.length ==1 ) menu.add_separator menu.add_item("get/set attributes") { get_set_attributes } end end #add a menu item to define attributes plugins_menu = UI.menu("Plugins") plugins_menu.add_item("Define attributes") { define_attributes } end def get_set_attributes object=Sketchup.active_model.selection.first dict=object.attribute_dictionaries[$dictname] prompts=dict.keys values=dict.collect { | key, value | object.get_attribute $dictname, key } title="get/set attributes" result=inputbox prompts,values,title if result c=-1; result.each {|newvalue| object.set_attribute $dictname, dict.keys[c+=1], newvalue} end end def add_attribute(name,value) $model.set_attribute $dictname, name, value end def remove_attribute(name) $dict.delete_key name end def define_attributes result=inputbox ["attributes"], [$dict.keys.join(" ")],"Define attributes as a space-separated list" if result ($dict.keys - result[0].split).each {|key| remove_attribute(key)} (result[0].split - $dict.keys).each {|key| add_attribute(key,"")} end end