|
SketchUp Ruby API Reference |
Parent: Drawingelement
Methods: all_connected, area, back_material, back_material= , classify_point, edges, followme, get_UVHelper, loops, mesh, normal, outer_loop, plane, position_material, pushpull, reverse!, vertices
Example Code: facetests.rb
The all_connected method retrieves all of the entities connected to a face.
entities = face.all_connected
entities - the entities connected to the face
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[0]
entities = entity1.all_connected
if (entities)
UI.messagebox entities
else
UI.messagebox "Failure"
end
The area method is used to retrieve the area of a face in current units.
area = face.area
area - the area of the face in current units (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
area = face.area
The back_material method is used to retrieve the material assigned to the back side of the face.
material = face.back_material
material - a Material object representing the material on the back of the face (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
area = face.area
back = face.back_material
The back_material= method is used to set the material assigned to the back side of the face.
material = face.back_material = "material_name" | material
"material_name" - the name of a valid material
material - a Material object
material - the name of the valid material or the new Material 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
status = face.back_material="red"
The classify_point method is used to.
The edges method is used to get an array of edges that bound the face.
edges = face.edges
edges - an array of Edge objects (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
edges = face.edges
The followme method is used creating a shape by making the face follow along an array of edges.
status = face.followme edge1, edge2, ...
status = face.followme [edge1, edge2, ...]
edge1 - an Edge object to follow
status - true if successful, nil if unsuccessful
point1 = Geom::Point3d.new (0,0,0)
point2 = Geom::Point3d.new (0,0,100)
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
line = entities.add_line point1, point2
begin
status = face.followme line
rescue
UI.messagebox $!.message
end
The get_UVHelper object is used to retrieve a UVHelper object for use in texture manipulation on a face.
uvhelper = face.get_UVHelper front, back, texturewriter
front - true if you want the texture coordinates for the front face, false if not
back - true if you want the texture coordinates for the back face, false if not
texturewriter - a TextureWriter object
uvhelper - a UVHelper object
uvHelp = face.get_UVHelper true, true, tw
The loops method is used to get an array of all of the loops that bound the face.
loops = face.loops
loops - an array of Loop objects if successful
point1 = Geom::Point3d.new (0,0,0)
point2 = Geom::Point3d.new (0,0,100)
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
loops = face.loops
The mesh method creates a polygon mesh that represents the face. See the PolygonMesh class for more information.
mesh = face.mesh flags
flags - one or more flags used to generate a polygon mesh (see comments)
mesh - a PolygonMesh object if successful
Valid flags are:
0 (Include PolygonMeshPoints)
1 (Include PolygonMeshUVQFront)
2 (Include PolygonMeshUVQBack)
4 (Include PolygonMeshNormals).
Add these numbers together to combine flags. A value of 5 will include
all flags, for example.
point1 = Geom::Point3d.new (0,0,0)
point2 = Geom::Point3d.new (0,0,100)
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 ptsmesh = face.mesh 7
The normal method is used to retrieve the 3d vector normal to the face in the front direction.
vector = face.normal
vector - a Vector3d object if successful
point1 = Geom::Point3d.new (0,0,0)
point2 = Geom::Point3d.new (0,0,100)
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 ptsnormal = face.normal
This method is used to retrieve the outer loop that bounds the face.
loop = face.outer_loop
loop - a Loop object representing the outer loop (if successful)
point1 = Geom::Point3d.new (0,0,0)
point2 = Geom::Point3d.new (0,0,100)
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
loop = face.outer_loop
The plane method is used to retrieve the plane of the face.
plane = face.plane
plane - a plane that contains the face (if successful)
point1 = Geom::Point3d.new (0,0,0)
point2 = Geom::Point3d.new (0,0,100)
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
plane = face.plane
The position_material method is used to position a material on a face.
face.position_material material, pt_array, on_front
material - a Material object
pt_array - an array of Point3d objects used to position the material
o_front - true to position the texture on the front of the Face or false to position it on the back of the Face.
The pt_array must contain 2, 4, 6 or 8 points. The points are used in pairs to tell where a point in the texture image is positioned on the Face. The first point in each pair is a 3D point in the model. It should be a point on the Face. The second point in each pair of points is a 2D point that gives the (u,v) coordinates of a point in the image to match up with the 3D point.
The pushpull method is used to perform a push/pull on a face.
face.pushpull distance copy
distance - the distance, in current units, to push/pull the face
copy - create a new push/pull starting face if true (equivalent of pressing CTRL while in SketchUp), do not create a push/pull starting face if false.
The distance is measured in the direction that the face normal is pointing.
point1 = Geom::Point3d.new (0,0,0)
point2 = Geom::Point3d.new (0,0,100)
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.pushpull 100, true
The reverse! method is used to reverse the face's orientation.
face = face.reverse!
face- the reversed Face object if successful, false if unsuccessful
point1 = Geom::Point3d.new (0,0,0)
point2 = Geom::Point3d.new (0,0,100)
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.reverse!
The vertices method is used to retrieve an array of vertexes used by the edges of the face.
vertices = face.vertices
vertices - an array of Vertex objects
point1 = Geom::Point3d.new (0,0,0)
point2 = Geom::Point3d.new (0,0,100)
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 ptsvertices = face.vertice