Browsed by
Tag: rotation

Interactive Mobius Strip Generator

Interactive Mobius Strip Generator

Compatible with WizoScript versions: 1.70

Shows how to prompt the user for information and then use that information to manipulate a part that the user is already working on. Requires Geomagic Design V16 hotfix 1 ( or later.

# creates a mobius strip with a configurable number of rotations
print "Create a new part with a 2D sketch on the XY plane"
print "Enter name of part: "
PartName = Read()
Mobius = Part(PartName, False)
print "Enter name of sketch on XY plane: "
SketchName = Read()
print "Enter rotation point along X axis: "
Diameter = float(Read())
print "Enter number of rotations: "
Rotations = int(Read())
print "Enter number of steps: "
Steps = int(Read())
# calculate how far we rotate through 360 degrees for each step
RotationPerStep = Rotations / float(Steps) * 360.0
DegreesPerStep = 360.0 / Steps
# get the base sketch
S0Plane = Mobius.GetPlane("XY-Plane")
S0 = Mobius.GetSketch(SketchName)
Sketches = [S0]
# generate sketches
for Step in range (1, Steps):
  Plane = Mobius.AddPlane("S" + str(Step), S0Plane, Mobius.GetAxis("Y-Axis"), DegreesPerStep * Step)
  Sketch = Mobius.AddSketch("S" + str(Step), Plane)
  Sketch.CopyFrom(S0, RotationPerStep * Step, Diameter, 0, 0, 0, 0, 0, 100.0)
# the last sketch is the same as the first to form a complete loop
# create loft
Mobius.AddLoftBoss("Strip", Sketches, False, False, False, False)
CSV Import with Point Rotation

CSV Import with Point Rotation

Compatible with WizoScript versions: 1.40

The following script shows how to import a set of 2D points from a CSV file, rotate them about a arbitrary point and then add them to a 2D sketch.

# imports a set of 2D points from a csv file, rotates them and then
# adds them to a 2D sketch with lines connecting the points
# specify which libraries we are going to use
import csv
import math
# configuration
angle = 30.5
rotationpoint = [5.0, 5.0]
csvfile = r"C:\Users\Andy\Example.csv"
# rotates a point around another point
# passed is the angle, the point to rotate and the origin of the rotation
# copied from
def rotate2d(degrees,point,origin):
  x = point[0] - origin[0]
  yorz = point[1] - origin[1]
  newx = (x*math.cos(math.radians(degrees))) - (yorz*math.sin(math.radians(degrees)))
  newyorz = (x*math.sin(math.radians(degrees))) + (yorz*math.cos(math.radians(degrees)))
  newx += origin[0]
  newyorz += origin[1] 
  return newx,newyorz
# list of points, empty for now
# points will be stored as [x1,y1, x2,y2, ... ,xn,yn]
points = []
# open csv file
f = open(csvfile)
# create csv reader and read in lines
reader = csv.reader(f)
for row in reader:
  # column 0 contains x, column 1 contains y
  x = float(row[0])
  y = float(row[1])
  # rotate point and add to list of points
  points.extend(rotate2d(angle, [x, y], rotationpoint))
# finished with csv file
# show number of points found
print "Found %d points" % (len(points) / 2)
# create part
MyPart = Part("My Part")
# add sketch on XY plane
PointSketch = MyPart.AddSketch("Point Sketch", MyPart.GetPlane("XY-Plane"))
# add points with lines connecting them
PointSketch.AddLines(points, False)