# 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 copyGroupTest 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 group to the entities in the model group = entities.add_group # Get the entities within the group entities2 = group.entities # Add a face to within the group face = entities2.add_face pts group2 = group.copy if (group2) UI.messagebox group2 else UI.messagebox "Failure" end end def descriptionGroupTest 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 group to the entities in the model group = entities.add_group # Get the entities within the group entities2 = group.entities # Add a face to within the group face = entities2.add_face pts group.description = "This is a Group with a 2d Face" description = group.description if (description) UI.messagebox description else UI.messagebox "Failure" end end def descriptionEqualsGroupTest 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 group to the entities in the model group = entities.add_group # Get the entities within the group entities2 = group.entities # Add a face to within the group face = entities2.add_face pts group.description = "This is a Group with a 2d Face" status = description = group.description if (description) UI.messagebox description UI.messagebox status else UI.messagebox "Failure" end end def entitiesGroupTest 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 group to the entities in the model group = entities.add_group # Get the entities within the group entities2 = group.entities # Add a face to within the group face = entities2.add_face pts entities = group.entities if (entities) UI.messagebox entities else UI.messagebox "Failure" end end def explodeGroupTest 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 group to the entities in the model group = entities.add_group # Get the entities within the group entities2 = group.entities # Add a face to within the group face = entities2.add_face pts UI.messagebox "Grouped" status = group.explode if (status) UI.messagebox "Exploded Group" else UI.messagebox "Failure" end end def lockedGroupTest 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 group to the entities in the model group = entities.add_group status = group.locked? UI.messagebox status end def moveGroupTest point = Geom::Point3d.new 500,500,500 t = Geom::Transformation.new point 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 group to the entities in the model group = entities.add_group # Get the entities within the group entities2 = group.entities # Add a face to within the group face = entities2.add_face pts UI.messagebox "Group before Move" group = group.move! t if (group) UI.messagebox "Group after move" UI.messagebox group else UI.messagebox "Failure" end end def nameGroupTest 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 group to the entities in the model group = entities.add_group # Get the entities within the group entities2 = group.entities # Add a face to within the group face = entities2.add_face pts group.name = "2d Face" name = group.name if (name) UI.messagebox name else UI.messagebox "Failure" end end def nameEqualsGroupTest 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 group to the entities in the model group = entities.add_group # Get the entities within the group entities2 = group.entities # Add a face to within the group face = entities2.add_face pts status = group.name = "2d Face" UI.messagebox status name = group.name if (name) UI.messagebox name else UI.messagebox "Failure" end end def transformGroupTest point = Geom::Point3d.new 500,500,500 t = Geom::Transformation.new point 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 group to the entities in the model group = entities.add_group # Get the entities within the group entities2 = group.entities # Add a face to within the group face = entities2.add_face pts UI.messagebox "Group before Move" group = group.transform! t if (group) UI.messagebox "Group after move" UI.messagebox group else UI.messagebox "Failure" end end def transformationGroupTest point = Geom::Point3d.new 500,500,500 t = Geom::Transformation.new point 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 group to the entities in the model group = entities.add_group # Get the entities within the group entities2 = group.entities # Add a face to within the group face = entities2.add_face pts UI.messagebox "Group before Move" group2 = group.move! t begin trans = group2.transformation rescue UI.messagebox $!.message end if (trans) UI.messagebox trans else UI.messagebox "Failure" end end def transformationEqualsGroupTest point = Geom::Point3d.new 500,500,500 t = Geom::Transformation.new point 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 group to the entities in the model group = entities.add_group # Get the entities within the group entities2 = group.entities # Add a face to within the group face = entities2.add_face pts UI.messagebox "Group before Move" trans = group.transformation=t if (trans) UI.messagebox trans else UI.messagebox "Failure" end end if( not file_loaded?("grouptests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") plugins_menu = UI.menu("Plugins") Group_menu = plugins_menu.add_submenu("Group Tests") Group_menu.add_item("Group.copy") { copyGroupTest } Group_menu.add_item("Group.description") { descriptionGroupTest } Group_menu.add_item("Group.description=") { descriptionEqualsGroupTest } Group_menu.add_item("Group.entities") { entitiesGroupTest } Group_menu.add_item("Group.explode") { explodeGroupTest } Group_menu.add_item("Group.locked?") { lockedGroupTest } Group_menu.add_item("Group.move!") { moveGroupTest } Group_menu.add_item("Group.name") { nameGroupTest } Group_menu.add_item("Group.name_equals") { nameEqualsGroupTest } Group_menu.add_item("Group.transform!") { transformGroupTest } Group_menu.add_item("Group.transformation") { transformationGroupTest } Group_menu.add_item("Group.transformation=") { transformationEqualsGroupTest } end #----------------------------------------------------------------------------- file_loaded("grouptests.rb")