# 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 attributeDictionariesEntityTest depth = 100 width = 100 model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts # I just happen to know that the second and third entities in the # entities objects are edges. entity1 = entities[1] status = entity1.set_attribute "testdictionary", "test", 115 attrdicts = entity1.attribute_dictionaries if (attrdicts) attrdict = attrcits[0] name = attrdict.name UI.messagebox name else UI.messagebox "Failure" end end def attributeDictionaryEntityTest depth = 100 width = 100 model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts # I just happen to know that the second and third entities in the # entities objects are edges. entity1 = entities[1] status = entity1.set_attribute "testdictionary", "test", 115 attrdict = entity1.attribute_dictionary "testdictionary" if (attrdict) UI.messagebox attrdict else UI.messagebox "Failure" end end def deleteAttributeEntityTest depth = 100 width = 100 model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts # I just happen to know that the second and third entities in the # entities objects are edges. entity1 = entities[1] entity1.set_attribute "testdictionary", "test", 115 status = entity1.delete_attribute "testdictionary" if (status) UI.messagebox status else UI.messagebox "Failure" end end def deletedEntityTest depth = 100 width = 100 model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts entity1 = entities[1] status = entity1.deleted? if (status) UI.messagebox status else UI.messagebox "Failure" end end def entityIDEntityTest depth = 100 width = 100 model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts entity1 = entities[1] id = entity1.entityID if (id) UI.messagebox id else UI.messagebox "Failure" end end def getAttributeEntityTest depth = 100 width = 100 model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts # I just happen to know that the second and third entities in the # entities objects are edges. entity1 = entities[1] entity1.set_attribute "testdictionary", "test", 115 value = entity1.get_attribute "testdictionary", "test" if (value) UI.messagebox value else UI.messagebox "Failure" end end def modelEntityTest depth = 100 width = 100 model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts # I just happen to know that the second and third entities in the # entities objects are edges. entity1 = entities[1] m = entity1.model if (m) UI.messagebox m else UI.messagebox "Failure" end end def parentEntityTest depth = 100 width = 100 model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts # I just happen to know that the second and third entities in the # entities objects are edges. entity1 = entities[1] parent = entity1.parent if (parent) UI.messagebox parent else UI.messagebox "Failure" end end def setAttributeEntityTest depth = 100 width = 100 model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts # I just happen to know that the second and third entities in the # entities objects are edges. entity1 = entities[1] status = entity1.set_attribute "testdictionary", "test", 115 if (status) UI.messagebox status else UI.messagebox status end end def toSEntityTest depth = 100 width = 100 model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts # I just happen to know that the second and third entities in the # entities objects are edges. entity1 = entities[1] st = entity1.to_s if (st) UI.messagebox st else UI.messagebox "Failure" end end def typenameEntityTest depth = 100 width = 100 model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts # I just happen to know that the second and third entities in the # entities objects are edges. entity1 = entities[1] type = entity1.typename if (type) UI.messagebox type else UI.messagebox "Failure" end end def validEntityTest depth = 100 width = 100 model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts entity1 = entities[1] status = entity1.valid? if (status) UI.messagebox status else UI.messagebox "Failure" end end if( not file_loaded?("entitytests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") plugins_menu = UI.menu("Plugins") Entity_menu = plugins_menu.add_submenu("Entity Tests") Entity_menu.add_item("Entity.attribute_dictionaries") { attributeDictionariesEntityTest } Entity_menu.add_item("Entity.attribute_dictionary") { attributeDictionaryEntityTest } Entity_menu.add_item("Entity.delete_attribute") { deleteAttributeEntityTest } Entity_menu.add_item("Entity.deleted?") { deletedEntityTest } Entity_menu.add_item("Entity.entityID") { entityIDEntityTest } Entity_menu.add_item("Entity.get_attribute") { getAttributeEntityTest } Entity_menu.add_item("Entity.model") { modelEntityTest } Entity_menu.add_item("Entity.parent") { parentEntityTest } Entity_menu.add_item("Entity.set_attribute") { setAttributeEntityTest } Entity_menu.add_item("Entity.to_s") { toSEntityTest } Entity_menu.add_item("Entity.typename") { typenameEntityTest } Entity_menu.add_item("Entity.valid?") { validEntityTest } end #----------------------------------------------------------------------------- file_loaded("entitytests.rb")