# 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 getDefinitionListTest path = Sketchup.find_support_file "BedTraditional.skp" ,"Components/Furniture/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path component = definitions[0] if (component) name = component.name UI.messagebox name else UI.messagebox "Failure" end end def addDefinitionListTest model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.add "BedTraditional" component = definitions[0] if (component) name = component.name UI.messagebox name else UI.messagebox "Failure" end end def atDefinitionListTest model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.add "BedTraditional" component = definitions.at 0 if (component) name = component.name UI.messagebox name else UI.messagebox "Failure" end end def countDefinitionListTest model = Sketchup.active_model definitions = model.definitions #componentdefinition = definitions.add "BedTraditional" number = definitions.count if (number) UI.messagebox number else UI.messagebox "Failure" end end def eachDefinitionListTest model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.add "BedTraditional" number = definitions.each {|definition| UI.messagebox definition } end def lengthDefinitionListTest model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.add "BedTraditional" number = definitions.count if (number) UI.messagebox number else UI.messagebox "Failure" end end def loadDefinitionListTest path = Sketchup.find_support_file "BedTraditional.skp" ,"Components/Furniture/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path if (componentdefinition) UI.messagebox componentdefinition else UI.messagebox "Failure" end end def uniqueNameDefinitionListTest path = Sketchup.find_support_file "BedTraditional.skp" ,"Components/Furniture/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path name = componentdefinition.name newname = definitions.unique_name name if (newname) UI.messagebox newname else UI.messagebox "Failure" end end if( not file_loaded?("definitionlisttests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") plugins_menu = UI.menu("Plugins") DefinitionList_menu = plugins_menu.add_submenu("DefinitionList Tests") DefinitionList_menu.add_item("DefinitionList.[]") { getDefinitionListTest } DefinitionList_menu.add_item("DefinitionList.add") { addDefinitionListTest } DefinitionList_menu.add_item("DefinitionList.at") { atDefinitionListTest } DefinitionList_menu.add_item("DefinitionList.count") { countDefinitionListTest } DefinitionList_menu.add_item("DefinitionList.each") { eachDefinitionListTest } DefinitionList_menu.add_item("DefinitionList.length") { lengthAngleDefinitionListTest } DefinitionList_menu.add_item("DefinitionList.load") { loadDefinitionListTest } DefinitionList_menu.add_item("DefinitionList.unique_name") { uniqueNameDefinitionListTest } end #----------------------------------------------------------------------------- file_loaded("definitionlisttests.rb")