Cylinder Between Two Points II

Cylinder Between Two Points II

Compatible with WizoScript 3.00 and later.

Inserts a cylinder between two points.

from math import sqrt

Win = Windows()

Options = []
Options.append(["Start Point", WindowsInputTypes.Point, None])
Options.append(["End Point", WindowsInputTypes.Point, None])
Options.append(["Diameter", WindowsInputTypes.Real, 5])

Values = Win.OptionsDialog("Cylinder", Options)
if Values == None:
  sys.exit()
if Values[0] == None:
  Win.ErrorDialog("No start point selected", "Cylinder")
  sys.exit()
if Values[1] == None:
  Win.ErrorDialog("No end point selected", "Cylinder")
  sys.exit()
if Values[2] <= 0:
  Win.ErrorDialog("Invalid diameter", "Cylinder")
  sys.exit()

# get the part that defines the first point
# it is possible the second point is on a different part but we will assume
# they are on the same part
P = Values[0].GetPart()

# get points and diameter
cyl_p1 = Values[0].GetCoordinates()
cyl_p2 = Values[1].GetCoordinates()
diameter = Values[2]

# 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 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)

Leave a Reply

Your email address will not be published. Required fields are marked *