# 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 sortCDTest path1 = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/" path2 = Sketchup.find_support_file "Office_Laptop.skp", "Components/Architecture_Sampler/" model = Sketchup.active_model definitions = model.definitions componentdefinition1 = definitions.load path1 componentdefinition2 = definitions.load path2 # Yields a -1 status = componentdefinition1 <=> componentdefinition2 if (status) UI.messagebox status else UI.messagebox "Failure" end # Yields a 1 status = componentdefinition2 <=> componentdefinition1 if (status) UI.messagebox status else UI.messagebox "Failure" end end def compareCDTest path1 = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/" path2 = Sketchup.find_support_file "Office_Laptop.skp", "Components/Architecture_Sampler/" model = Sketchup.active_model definitions = model.definitions componentdefinition1 = definitions.load path1 componentdefinition2 = definitions.load path2 status = componentdefinition1 == componentdefinition2 if (status) UI.messagebox status else UI.messagebox status UI.messagebox "Components are Not the Same" end end def behaviorCDTest path = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path behavior = componentdefinition.behavior if (behavior) UI.messagebox behavior else UI.messagebox "Failure" end end def countInstancesCDTest path = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path number = componentdefinition.count_instances if (number) UI.messagebox number else UI.messagebox "Failure" end end def descriptionCDTest path = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path componentdefinition.description="This is a traditional bed" description = componentdefinition.description if (description) UI.messagebox description else UI.messagebox "Failure" end end def descriptionEqualsCDTest path = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path componentdefinition.description="This is a traditional bed" description = componentdefinition.description if (description) UI.messagebox description else UI.messagebox "Failure" end end def entitiesCDTest path = Sketchup.find_support_file "fan.skp" ,"v" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path entities = componentdefinition.entities if (entities) length = entities.length UI.messagebox "Number of Entities in Component: #{length}" else UI.messagebox "Failure" end end def groupCDTest path = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path status = componentdefinition.group? if (status) UI.messagebox status else UI.messagebox "No Groups in the Component" end end def guidCDTest path = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path guid = componentdefinition.guid if (guid) UI.messagebox guid else UI.messagebox "Failure: No GUID" end end def hiddenCDTest path = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path status = componentdefinition.hidden? if (status) UI.messagebox "Component should be hidden on the Component Browser" else UI.messagebox status UI.messagebox "Component should not be hidden on the Component Browser" end end def imageCDTest path = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path status = componentdefinition.image? if (status) UI.messagebox "Component definition defines an image" else UI.messagebox status UI.messagebox "Component definition does not define an image" end end def instancesCDTest path = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path instances = componentdefinition.instances if (instances) UI.messagebox instances else UI.messagebox "Failure" end end def insertionPointCDTest point = Geom::Point3d.new 10,20,30 transform = Geom::Transformation.new point model = Sketchup.active_model entities = model.active_entities path = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/" definitions = model.definitions componentdefinition = definitions.load path instance = entities.add_instance componentdefinition, transform point = componentdefinition.insertion_point if (point) UI.messagebox point else UI.messagebox "Component not inserted" end end def nameCDTest path = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path name = componentdefinition.name if (name) UI.messagebox name else UI.messagebox "Failure" end end def nameEqualsCDTest path = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path name = componentdefinition.name="Bed" if (name) UI.messagebox name else UI.messagebox "Failure" end end def pathCDTest path = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path path = componentdefinition.path if (path) UI.messagebox path else UI.messagebox "Failure" end end def saveThumbnailCDTest path = Sketchup.find_support_file "fan.skp" ,"Components/Architecture_Sampler/" model = Sketchup.active_model definitions = model.definitions componentdefinition = definitions.load path status = componentdefinition.save_thumbnail "testthumbnail.jpg" UI.messagebox status end if( not file_loaded?("cdtests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") plugins_menu = UI.menu("Plugins") cd_menu = plugins_menu.add_submenu("Component Definition Tests") cd_menu.add_item("ComponentDefinition.<=>") { sortCDTest } cd_menu.add_item("ComponentDefinition.==") { compareCDTest } cd_menu.add_item("ComponentDefinition.behavior") { behaviorCDTest } cd_menu.add_item("ComponentDefinition.count_instances") { countInstancesCDTest } cd_menu.add_item("ComponentDefinition.description") { descriptionCDTest } cd_menu.add_item("ComponentDefinition.description=") { descriptionEqualsCDTest } cd_menu.add_item("ComponentDefinition.entities") { entitiesCDTest } cd_menu.add_item("ComponentDefinition.group?") { groupCDTest } cd_menu.add_item("ComponentDefinition.guid") { guidCDTest } cd_menu.add_item("ComponentDefinition.hidden?") { hiddenCDTest } cd_menu.add_item("ComponentDefinition.hidden?") { instancesCDTest } cd_menu.add_item("ComponentDefinition.image?") { imageCDTest } cd_menu.add_item("ComponentDefinition.insertion_point") { insertionPointCDTest } cd_menu.add_item("ComponentDefinition.name") { nameCDTest } cd_menu.add_item("ComponentDefinition.name=") { nameEqualsCDTest } cd_menu.add_item("ComponentDefinition.path") { pathCDTest } cd_menu.add_item("ComponentDefinition.save_thumbnail") { saveThumbnailCDTest } end #----------------------------------------------------------------------------- file_loaded("cdtests.rb")