## Creating a Cylinder Between Two Points

Compatible with WizoScript versions: 1.85 Shows how to create a plane with a specific normal and project 3D points to 2D sketches.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# creates a cylinder between two arbitrary points from math import sqrt # ends of cylinder are centered on these points cyl_p1 = [1, 5, 2] cyl_p2 = [10, 14, 8] # diameter of cylinder diameter = 6 # get length of cynlinder using euclidean distance length = sqrt((cyl_p2[0] - cyl_p1[0])**2 + (cyl_p2[1] - cyl_p1[1])**2 + (cyl_p2[2] - cyl_p1[2])**2) # calculate normal vector for the plane at the first end of the cylinder normal_vector = [cyl_p2[0] - cyl_p1[0], cyl_p2[1] - cyl_p1[1], cyl_p2[2] - cyl_p1[2]] # create part P = Part('Cylinder') # create plane for one end of the cylinder cyl_plane = P.AddPlane('Cyl Start Plane', normal_vector, cyl_p1) P.AddAxis('Cylinder Axis', cyl_p1, cyl_p2) # draw a circle on the plane S = P.AddSketch('Cylinder End', cyl_plane) [cx, cy] = S.GlobaltoPoint(cyl_p1[0], cyl_p1[1], cyl_p1[2]) S.AddCircle(cx, cy, diameter, False) # extrude into a cylinder P.AddExtrudeBoss('Cylinder', S, length, True) |