# 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 boundsDrawingElementTest 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 # Remember, anything that can be displayed, such as a face, is also # a DrawingElement. So, I can call bounds on a face and because face # sub-classes DrawingElement. boundingbox = face.bounds if (boundingbox) UI.messagebox boundingbox else UI.messagebox "Failure" end end def eraseDrawingElementTest 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 UI.messagebox "Click OK to Erase the Box" # Remember, anything that can be displayed, such as a face, is also # a DrawingElement. So, I can call bounds on a face and because face # sub-classes DrawingElement. # Returns nil if successful status = face.erase! if (status) UI.messagebox status else UI.messagebox "Face Erased" end end def hiddenEqualsDrawingElementTest 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 UI.messagebox "Click OK to Hide the Box" status = face.hidden=true if (status) UI.messagebox status else UI.messagebox "Failure" end end def hiddenDrawingElementTest 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 status = face.hidden? if (status) UI.messagebox "Hidden" else UI.messagebox status UI.messagebox "Not Hidden" end end def layerDrawingElementTest 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 layer = face.layer if (layer) name = layer.name UI.messagebox name else UI.messagebox "Failure" end end def layerEqualsDrawingElementTest model = Sketchup.active_model layers = model.layers 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 # Add a layer layer = layers.add "joe" # Put the face on the joe layer (instead of layer 0) newlayer = face.layer=layer if (newlayer) name = newlayer.name UI.messagebox name else UI.messagebox "Failure" end end def materialDrawingElementTest model = Sketchup.active_model layers = model.layers 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 material = face.material if (material) UI.messagebox material else UI.messagebox "No Material Associated with Entity" end end def materialEqualsDrawingElementTest model = Sketchup.active_model materials = model.materials layers = model.layers 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 m = materials.add "Joe" begin # Returns nil if not successful, path if successful. Should return a texture object m.texture="c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg" rescue UI.messagebox $!.message end # You will see the material applied when you reverse the box's faces material = face.material=m if (material) name = material.name UI.messagebox name else UI.messagebox "Failure Adding Material" end end def visibleEqualsDrawingElementTest 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 UI.messagebox "Click OK to Hide the Box" status = face.visible=false if (status) UI.messagebox status else UI.messagebox status end end def visibleDrawingElementTest 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 status = face.visible? if (status) UI.messagebox "Visible" else UI.messagebox "Not Visible" end end if( not file_loaded?("drawingelementtests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") plugins_menu = UI.menu("Plugins") DrawingElement_menu = plugins_menu.add_submenu("DrawingElement Tests") DrawingElement_menu.add_item("DrawingElement.bounds") { boundsDrawingElementTest } DrawingElement_menu.add_item("DrawingElement.erase") { eraseDrawingElementTest } DrawingElement_menu.add_item("DrawingElement.hidden=") { hiddenEqualsDrawingElementTest } DrawingElement_menu.add_item("DrawingElement.hidden") { hiddenDrawingElementTest } DrawingElement_menu.add_item("DrawingElement.layer") { layerDrawingElementTest } DrawingElement_menu.add_item("DrawingElement.layer=") { layerEqualsDrawingElementTest } DrawingElement_menu.add_item("DrawingElement.material") { materialDrawingElementTest } DrawingElement_menu.add_item("DrawingElement.material=") { materialEqualsDrawingElementTest } DrawingElement_menu.add_item("DrawingElement.visible=") { visibleEqualsDrawingElementTest } DrawingElement_menu.add_item("DrawingElement.visible") { visibleDrawingElementTest } end #----------------------------------------------------------------------------- file_loaded("drawingelementtests.rb")