# 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 allConnectedEdgeTest 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] entity2 = entities[2] edges = entity1.all_connected if (edges) UI.messagebox edges else UI.messagebox "Failure" end end # Accepts a second edge as a input. def commonFaceEdgeTest 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] entity2 = entities[2] UI.messagebox entity1 UI.messagebox entity2 face = entity1.common_face entity2 if (face) UI.messagebox face else UI.messagebox "Failure: No Common Face" end end def curveEdgeTest 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 entity in the # entities objects is an edge. entity1 = entities[5] begin curve = entity1.curve rescue UI.messagebox $!.message end if (curve) UI.messagebox curve else UI.messagebox "Failure: No Curve" end end def endEdgeTest 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 entity in the # entities objects is an edge. entity1 = entities[1] # Returns a vertex vertex = entity1.end if (vertex) UI.messagebox vertex else UI.messagebox "Failure" end point = vertex.position if (point) UI.messagebox point else UI.messagebox "Failure" end end def explodeCurveTest 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 entity in the # entities objects is an edge. entity1 = entities[1] curve = entity1.explode_curve if (curve) UI.messagebox curve else UI.messagebox "Failure" end end def facesEdgeTest 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 entity in the # entities objects is an edge. entity1 = entities[1] faces = entity1.faces if (faces) UI.messagebox faces[0] else UI.messagebox "Failure" end end def findFacesEdgeTest 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 entity in the # entities objects is an edge. entity1 = entities[1] # Getting zero. number = entity1.find_faces if (number) UI.messagebox number else UI.messagebox "Failure" end end def lengthEdgeTest 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 entity in the # entities objects is an edge. entity1 = entities[1] begin length = entity1.length rescue UI.messagebox $!.message end if (length) UI.messagebox length else UI.messagebox "Failure" end end def lineEdgeTest 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 entity in the # entities objects is an edge. entity1 = entities[1] # Returns a 3d Ray line = entity1.line if (line) UI.messagebox line else UI.messagebox "Failure" end end def otherVertexEdgeTest # Provide it with one vertex for an edge, and you get back the # other vertex. 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 entity in the # entities objects is an edge. entity1 = entities[1] # Returns a vertex vertex = entity1.end # Should find the starting vertex othervertex = entity1.other_vertex vertex if (othervertex) UI.messagebox othervertex else UI.messagebox "Failure" end point = othervertex.position if (point) UI.messagebox point else UI.messagebox "Failure" end end def reversedInEdgeTest # Returns an true if edge is reversed from its EdgeUse. Requires # A face for the corresponding edge. 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 entity in the # entities objects is an edge. UI.messagebox entities[4] entity = entities[1] begin status = entity.reversed_in? entities[4] rescue UI.messagebox $!.message end if (status) UI.messagebox status else UI.messagebox "Failure" end end def smoothEqualsEdgeTest 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 entity in the # entities objects is an edge. entity = entities[1] status = entity.smooth? if (status) UI.messagebox "Smooth" else UI.messagebox "Not Smooth" end status = entity.smooth="true" if (status) UI.messagebox "Smooth" else UI.messagebox "Not Smooth" end end def smoothEdgeTest 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 entity in the # entities objects is an edge. entity = entities[1] status = entity.smooth? if (status) UI.messagebox "Smooth" else UI.messagebox "Not Smooth" end end def softEqualsEdgeTest 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 entity in the # entities objects is an edge. entity = entities[1] status = entity.soft? if (status) UI.messagebox "Soft" else UI.messagebox "Not Soft" end status = entity.smooth="true" if (status) UI.messagebox "Soft" else UI.messagebox "Not Soft" end end def softEdgeTest 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 entity in the # entities objects is an edge. entity = entities[1] status = entity.soft? if (status) UI.messagebox "Soft" else UI.messagebox "Not Soft" end end # Accepts a Point3d def splitEdgeTest 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 entity in the # entities objects is an edge. entity = entities[1] vertex = entity.end # Get a Point3d for the end vertex position = vertex.position UI.messagebox position # Get the y value (the only value that changes between beginning and # end verticies) y = position.y # Returing 8' 4" or 100" # Divide the y value by 2 to get a new y value that is 1/2 the distance between # start and end verticies newy = y / 2 # Put the new y position in the Point3d object position.y=newy # Split the edge with the new Point3d object (should get 2 edges on # right-hand side of square) UI.messagebox position edge = entity.split position if (edge) UI.messagebox edge else UI.messagebox "Failure" end end def startEdgeTest 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 entity in the # entities objects is an edge. entity1 = entities[1] # Returns a vertex vertex = entity1.start if (vertex) UI.messagebox vertex else UI.messagebox "Failure" end point = vertex.position if (point) UI.messagebox point else UI.messagebox "Failure" end end # Accepts a vertex or a face def usedByEdgeTest 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 entity in the # entities objects is an edge. entity1 = entities[1] # Returns a vertex vertex = entity1.start # Check to see if the vertex is used by the edge status = entity1.used_by? vertex if (status) UI.messagebox status else UI.messagebox "Failure" end end def verticesEdgeTest 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 entity in the # entities objects is an edge. entity1 = entities[1] # Returns an array with two verticies for an edge. vertices = entity1.vertices if (vertices) UI.messagebox vertices else UI.messagebox "Failure" end # Let's look at the first vertex vertex = vertices[0] point = vertex.position UI.messagebox point end if( not file_loaded?("edgetests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") plugins_menu = UI.menu("Plugins") Edge_menu = plugins_menu.add_submenu("Edge Tests") Edge_menu.add_item("Edge.all_connected") { allConnectedEdgeTest } Edge_menu.add_item("Edge.common_face") { commonFaceEdgeTest } Edge_menu.add_item("Edge.curve") { curveEdgeTest } Edge_menu.add_item("Edge.end") { endEdgeTest } Edge_menu.add_item("Edge.explode_curve") { explodeCurveTest } Edge_menu.add_item("Edge.faces") { facesEdgeTest } Edge_menu.add_item("Edge.find_faces") { findFacesEdgeTest } Edge_menu.add_item("Edge.length") { lengthEdgeTest } Edge_menu.add_item("Edge.line") { lineEdgeTest } Edge_menu.add_item("Edge.other_vertex") { otherVertexEdgeTest } Edge_menu.add_item("Edge.reversed_in?") { reversedInEdgeTest } Edge_menu.add_item("Edge.smooth=") { smoothEqualsEdgeTest } Edge_menu.add_item("Edge.smooth?") { smoothEdgeTest } Edge_menu.add_item("Edge.soft=") { softEqualsEdgeTest } Edge_menu.add_item("Edge.soft?") { softEdgeTest } Edge_menu.add_item("Edge.split") { splitEdgeTest } Edge_menu.add_item("Edge.start") { startEdgeTest } Edge_menu.add_item("Edge.used_by") { usedByEdgeTest } Edge_menu.add_item("Edge.verticies") { verticesEdgeTest } end #----------------------------------------------------------------------------- file_loaded("edgetests.rb")