# 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 attrDictArrayTest model = Sketchup.active_model value = model.set_attribute "testdictionary", "test", 115 attrdicts = model.attribute_dictionaries attrdict = attrdicts["testdictionary"] value = attrdict["test"] if (attrdict) UI.messagebox value else UI.messagebox "Failure" end end #Returns the value the new value def attrDictArrayEqualsTest model = Sketchup.active_model value = model.set_attribute "testdictionary", "test", 115 attrdicts = model.attribute_dictionaries attrdict = attrdicts["testdictionary"] value = attrdict["test2"]=120 if (value) UI.messagebox value else UI.messagebox "Failure" end end # Actually returns the value of the deleted key def deleteKeyTest model = Sketchup.active_model value = model.set_attribute "testdictionary", "test", 115 attrdicts = model.attribute_dictionaries attrdict = attrdicts["testdictionary"] value = attrdict.delete_key("test") value = attrdict["test"] if (!value) UI.messagebox "Success: Deleted" else UI.messagebox "Failure" end end def eachTest model = Sketchup.active_model value = model.set_attribute "testdictionary", "test", 115 value = model.set_attribute "testdictionary", "test2", 120 value = model.set_attribute "testdictionary", "test3", 125 attrdicts = model.attribute_dictionaries attrdict = attrdicts["testdictionary"] attrdict.each { | key, value | UI.messagebox key } end def eachKeyTest model = Sketchup.active_model value = model.set_attribute "testdictionary", "test", 115 value = model.set_attribute "testdictionary", "test2", 120 value = model.set_attribute "testdictionary", "test3", 125 attrdicts = model.attribute_dictionaries attrdict = attrdicts["testdictionary"] attrdict.each_key { | key | UI.messagebox key } end def keysTest model = Sketchup.active_model value = model.set_attribute "testdictionary", "test", 115 value = model.set_attribute "testdictionary", "test2", 120 value = model.set_attribute "testdictionary", "test3", 125 attrdicts = model.attribute_dictionaries attrdict = attrdicts["testdictionary"] keys = attrdict.keys if (keys) UI.messagebox keys[0] else UI.messagebox "Failure" end end def lengthTest model = Sketchup.active_model value = model.set_attribute "testdictionary", "test", 115 value = model.set_attribute "testdictionary", "test2", 120 value = model.set_attribute "testdictionary", "test3", 125 attrdicts = model.attribute_dictionaries attrdict = attrdicts["testdictionary"] length = attrdict.length if (length) UI.messagebox length else UI.messagebox "Failure" end end def nameTest model = Sketchup.active_model value = model.set_attribute "testdictionary", "test", 115 value = model.set_attribute "testdictionary", "test2", 120 value = model.set_attribute "testdictionary", "test3", 125 attrdicts = model.attribute_dictionaries attrdict = attrdicts["testdictionary"] name = attrdict.name if (name) UI.messagebox name else UI.messagebox "Failure" end end def valuesTest model = Sketchup.active_model value = model.set_attribute "testdictionary", "test", 115 value = model.set_attribute "testdictionary", "test2", 120 value = model.set_attribute "testdictionary", "test3", 125 attrdicts = model.attribute_dictionaries attrdict = attrdicts["testdictionary"] values = attrdict.values if (values) UI.messagebox values[0] else UI.messagebox "Failure" end end if( not file_loaded?("arraydicttests.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 Dictionary Tests") AttrDictTest_menu.add_item("AttributeDictonary.[]") { attrDictArrayTest } AttrDictTest_menu.add_item("AttributeDictionary.[]=") { attrDictArrayEqualsTest } AttrDictTest_menu.add_item("AttributeDictionary.delete_key") { deleteKeyTest } AttrDictTest_menu.add_item("AttributeDictionary.each") { eachTest } AttrDictTest_menu.add_item("AttributeDictionary.each_key") { eachKeyTest } AttrDictTest_menu.add_item("AttributeDictionary.keys") { keysTest } AttrDictTest_menu.add_item("AttributeDictionary.length") { lengthTest } AttrDictTest_menu.add_item("AttributeDictionary.name") { nameTest } AttrDictTest_menu.add_item("AttributeDictionary.values") { valuesTest } end #----------------------------------------------------------------------------- file_loaded("arraydicttests.rb")