# Copyright 2005, @Last Software, Inc. # This software is provided as an example of using the Ruby interface # to SketchUp. # Permission to use, copy, modify, and distribute this software for # any purpose and without fee is hereby granted, provided that the above # copyright notice appear in all copies. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. #----------------------------------------------------------------------------- require 'sketchup.rb' #----------------------------------------------------------------------------- def attrDictsArrayTest model = Sketchup.active_model value = model.set_attribute "testdictionary", "test", 115 attrdicts = model.attribute_dictionaries begin attrdict = attrdicts["testdictionary"] rescue UI.messagebox $!.message end if (attrdict) value = attrdict["test"] UI.messagebox value else UI.messagebox "Failure" end end # Can take an attribute dictionary or the attribute dictionary name def deleteTest model = Sketchup.active_model value = model.set_attribute "testdictionary", "test", 115 attrdicts = model.attribute_dictionaries attrdict = attrdicts["testdictionary"] begin status = attrdicts.delete(attrdict) rescue UI.messagebox $!.message end if (status) UI.messagebox status UI.messagebox "Success: Item Deleted" else UI.messagebox "Failure" end end def eachDictionaryTest model = Sketchup.active_model value = model.set_attribute "testdictionary", "test", 115 value = model.set_attribute "testdictionary2", "test2", 120 value = model.set_attribute "testdictionary3", "test3", 125 dictionaries = model.attribute_dictionaries success = dictionaries.each { | attrdict | UI.messagebox attrdict } UI.messagebox success end if( not file_loaded?("attrdictstests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") plugins_menu = UI.menu("Plugins") AttrDictTest_menu = plugins_menu.add_submenu("Attribute Dictionaries Tests") AttrDictTest_menu.add_item("AttributeDictonaries.[]") { attrDictsArrayTest } AttrDictTest_menu.add_item("AttributeDictionaries.delete") { deleteTest } AttrDictTest_menu.add_item("AttributeDictionaries.each") { eachDictionaryTest } end #----------------------------------------------------------------------------- file_loaded("attrdictstests.rb")