The Workplane.line()
method is used to create a straight line segment between two points on a 3D workplane in the CADQuery Python library. It is particularly useful for creating precise geometry in parametric 3D modeling.
The syntax of the Workplane.line()
method is as follows:
lineSegment = Workplane.line(point1, point2)
Where:
lineSegment
is the resulting Edge
object that represents the line segment.point1
and point2
are 3-element tuples representing the X, Y, and Z coordinates of the two endpoints of the line segment.Here's an example that shows how to use the Workplane.line()
method to create a line segment between two points:
import cadquery as cq
# Create a 50x50x50mm block
block = cq.Workplane("XY").box(50, 50, 50)
# Get a face on the block
face = block.faces(">Z").first()
# Draw a line segment on the face
lineSegment = face.workplane().line((10, 10, 0), (40, 40, 0))
# Extrude the line segment
extruded = lineSegment.toPending().extrude(10)
# Display the result
show_object(extruded)
In this example, we create a 50x50x50mm block and get a face on the top of it. We then use the Workplane.line()
method to draw a line segment between two points (10, 10, 0)
and (40, 40, 0)
on the face. Finally, we extrude the resulting line segment by 10mm and display the result.
The Workplane.line()
method is a powerful tool for creating precise geometry in parametric 3D modeling with the CADQuery Python library. By using this method, you can easily create straight line segments between two points on a workplane, which can be extruded or used as the basis for other geometric operations.