The lineTo()
method is used in CadQuery to create a straight line between two points on a Workplane object. The method takes in two parameters which represent the x, y, and z coordinates of the starting and ending points of the line.
lineTo(x, y, z=None)
x
: The x-coordinate of the ending point of the line.y
: The y-coordinate of the ending point of the line.z
: (Optional) The z-coordinate of the ending point of the line. If not specified, the line will be created on the current Workplane plane.The lineTo()
method does not return any value. It creates a line segment as a child of the current Solid object.
import cadquery as cq
# Create a new workplane at the origin
wp = cq.Workplane("XY")
# Draw a line from (0,0) to (1,1) and add it to the workplane
wp.lineTo(1, 1)
# Draw another line from (1,1) to (2,1) and add it to the workplane
wp.lineTo(2, 1)
# Create a 3D object using the workplane
result = wp.extrude(0.5)
# Display the result
show_object(result)
This code creates a workplane at the origin (0,0,0) and then draws two straight line segments using the lineTo()
method. These line segments are then extruded to create a 3D object, which is displayed using the show_object()
method.
lineTo()
method must be called on a Workplane object.z
parameter is not specified, the line will be created on the current Workplane plane.