|
SketchUp Ruby API Reference |
The Edge class contains methods modifying and extracting information for edges.
Parent: Drawingelement
Methods: all_connected,common_face, curve, end, explode_curve, faces, find_faces, length, line, other_vertex, reversed_in?, smooth=, smooth?, soft=, soft?, split, start, used_by?, vertices
Example Code: edgetests.rb
The all_connected method retrieves all of the entities connected to an edge.
entities = edge.all_connected
entities - the entities connected to the 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 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
The common_face method is used to identify a face that is common to two edges.
face = edge1.common_face edge2
edge2 - the face whose edge you are checking for commonality
face - the Face object that is common to the two edges if successful
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 know that the second and third entity 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
The curve method is used to determine if an edge to see if it is a ArcCurve object.
arccurve = edge.curve
arccurve - returns an ArcCurve object if it is a curve, false if it is not a curve
curve = edge.curve
if (curve)
# if it is a curve, display a pointer to the curve
UI.messagebox curve
else
UI.messagebox "Failure: Not a Curve"
end
The end method is used to retrieve the Vertex object at the end of the edge.
vertex = edge.end
vertex - a Vertex object if successful
vertex = edge.end
if (vertex)
# display a pointer to the Vertex
UI.messagebox vertex
else
UI.messagebox "Failure"
end
point = vertex.position
# Let's get the Point3d of the vertex
if (point)
UI.messagebox point
else
UI.messagebox "Failure"
The explode_curve method is used to explode an edge as though it were an ArcCurve
edge = edge.explode_curve
edge - an exploded edge object if successful
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
The faces method is used to retrieve all of the faces common to the edge.
faces edge.faces
faces - an array of Face objects if successful, false if unsuccessful
faces = edge.faces
if (faces)
# Display the pointer to the first face returned in the array
UI.messagebox faces[0]
else
UI.messagebox "Failure: No Faces Found"
end
The find_faces method is used to find all Face objects that were created with this edge
number = edge.find_faces
number - the number of faces found
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
The length method is used to retrieve the length of an edge in current units.
length = edge.length
length - the length of the edge in current units
length = edge.length
if (length)
UI.messagebox length
The line method is used to retrieve the line defined by the edge.
line = edge.line
line - an array with a Point3d object and a Vector3d object.
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 know that the second and entity object is an edge
entity1 = entities[1]
# Returns a 3d ray
line = edge.line
if (line)
# Result is (100" 0", 0") (0.0, 1.0, 0.0)
UI.messagebox line
else
UI.messagebox "Failure"
end
The other_vertex method is used to find the opposite vertex given one vertex of the edge.
vertex2 = edge.other_vertex vertex1
vertex1 - one of the Vertex objects associated with the edge
vertex2 - the other Vertex object associated with the edge
# Get the end vertex of an edge
vertex = edge.end
# Should find the starting vertex
othervertex = edge.other_vertex vertex
if (othervertex)
UI.messagebox othervertex
else
UI.messagebox "Failure"
end
# The Point3d for the vertex
point = othervertex.position
if (point)
UI.messagebox point
else
UI.messagebox "Failure"
The reversed_in? method is used to determine if the EdgeUse object is traversed in the corresponding direction as its corresponding edge.
status = edge.reversed_in? face
face - the Face object that is bounded by the edge.
status - true if the edge is reversed, nil if it is not reversed.
begin
# When the geometry is a 2d rectangle with four edges, the face itself
# is entities[4]
status = entity.reversed_in? entities[4]
rescue
UI.messagebox $!.message end
if (status)
UI.messagebox status
else
UI.messagebox "Failure"
The smooth= method is used to set the edge to be smooth.
status = entity.smooth= value
value - true if you want the edge to be smooth, false if you do not want the edge to be smooth
status - true if successful, false if unsuccessful
# Examine the current smooth setting on an edge
status = entity.smooth?
if (status)
# If true, set it to false
UI.messagebox "Smooth"
status = entity.smooth="false"
else
# if false, set it to true
UI.messagebox 'Not Smooth"
status = entity.smooth="true"
end
The smooth? method is used to retrieve the current smooth setting for an edge.
status = edge.smooth?
status - true if smooth, false if not smooth
# Examine the current smooth setting on an edge
status = entity.smooth?
if (status)
# If true, set it to false
UI.messagebox "Smooth"
status = entity.smooth="false"
else
# if false, set it to true
UI.messagebox 'Not Smooth"
status = entity.smooth="true"
end
The smooth= method is used to set the edge to be soft.
status = entity.soft = value
value - true if you want the edge to be soft, false if you do not want the edge to be soft
status - true if successful, false if unsuccessful
# Examine the current soft setting on an edge
status = entity.soft?
if (status)
# If true, set it to false
UI.messagebox "Soft"
status = entity.soft="false"
else
# if false, set it to true
UI.messagebox 'Not Soft"
status = entity.soft="true"
end
The soft? method is used to retrieve the current smooth setting for an edge.
status = edge.soft?
status - true if soft, false if not soft
# Examine the current soft setting on an edge
status = entity.soft?
if (status)
# If true, set it to false
UI.messagebox "Soft"
status = entity.soft="false"
else
# if false, set it to true
UI.messagebox 'Not Soft"
status = entity.soft="true"
end
The split method is used to to split an edge into to or more distinct edges.
edge = edge.split position
position - a Point3d object whose location is along the edge
edge - an Edge object if successful
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 # Returning 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
UI.messagebox positionposition.y=newy# Split the edge with the new Point3d object (should get 2 edges on# right-hand side of square)edge = entity.split positionif (edge)UI.messagebox edgeelseUI.messagebox "Failure"end
The end method is used to retrieve the Vertex object at the start of the edge.
vertex = edge.start
vertex - a Vertex object if successful
vertex = edge.start
if (vertex)
# display a pointer to the Vertex
UI.messagebox vertex
else
UI.messagebox "Failure"
end
point = vertex.position
# Let's get the Point3d of the vertex
if (point)
UI.messagebox point
else
UI.messagebox "Failure"
end
The used_by? method is used to see if a vertex is used by an edge.
status = edge.usedby? vertex
vertex - a Vertex object
status - true if the vertex belongs to the edge, false if the vertex does not belong to the edge
# 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
The vertices method is used to retrieve an Array object consisting of the two vertices for an edge.
vertices = edge.vertices
vertices - an Array object of two Vertex objects
vertices = entity1.vertices
if (vertices)
UI.messagebox vertices
else
UI.messagebox "Failure"
end
# Examine the first vertex
vertex = vertices[0]
point = vertex.position
UI.messagebox point
|
SketchUp Ruby API Reference: Edge |
© Google Inc. 2007 sketchup.google.com |