Compatible with WizoScript versions: 1.40

This script takes an IGES file containing a set of points, identifies where to split the data, imports into multiple 3D sketches and adds bspline through the point in each sketch. For example it can be used with scanning data from a Romer arm.

# imports points from an IGES file into a 3D sketch
# splits the points up into segments and creates bsplines through the points for each segment
# requires wizoscript 1.40 and later
# specify which libraries we are going to use
import re
import math
# maximum distance between points before we create a new segment
maximumdistance = 3.9
# calculates distance between two points
# passed are two lists, [x1, y1, z1] and [x2, y2, z2]
def PointDistance(p1, p2):
return math.sqrt((p2[0] - p1[0])**2 + (p2[1] - p1[1])**2 + (p2[2] - p1[2])**2)
# adds a sketch to a part
def CreateSketch(part, name, points):
# add 3d sketch
Sketch = part.Add3DSketch(name)
# create bspline in sketch using points
Sketch.AddBspline(points)
# this pattern matches lines in the IGES file that define a point and specifies where in the line x, y and z are
igespointline = re.compile('^116,([0-9EeDd\.\-]+),([0-9EeDd\.\-]+),([0-9EeDd\.\-]+),.*[0-9]P.*$', re.IGNORECASE)
# list of points, empty for now
# points will be stored as [x1,y1,z1, x2,y2,z2, ... , xn,yn,zn]
points = []
previouspoint = []
# create part
MyPart = Part("My Part")
# open IGES file for reading
f = open(r"C:\Users\Andy\Downloads\IGES_POINTS_TEST_FOR_2.igs")
# read in lines from IGES file looking for points
for line in f:
# check if the line defines a point
match = igespointline.match(line)
if match != None:
# line defines a point, read out the coordinates
# note that we replace the 'D' with an 'E' to allow python to understand the value
x = float(match.group(1).upper().replace('D', 'E'))
y = float(match.group(2).upper().replace('D', 'E'))
z = float(match.group(3).upper().replace('D', 'E'))
# creates the new point
newpoint = [x, y, z]
# get distance from previous point
distance = 0.0
if len(previouspoint) > 1:
distance = PointDistance(previouspoint, newpoint)
# points close together?
if distance < maximumdistance:
# add to list of points
points.extend(newpoint)
previouspoint = newpoint
else:
# points too far apart, create the sketch of what we have so far
# show number of points found
print "Found %d points" % (len(points) / 3)
print "Creating 3D Sketch..."
CreateSketch(MyPart, "Sketch", points)
# restart with latest point
points = list(newpoint)
previouspoint = newpoint
# finished with IGES file
f.close()
# create sketch for remainder
if len(points) > 1:
# show number of points found
print "Found %d points" % (len(points) / 3)
print "Creating 3D Sketch..."
CreateSketch(MyPart, "Sketch", points)