Browsed by
Tag: converter

Importer for IGES Point Files

Importer for IGES Point Files

Compatible with WizoScript versions: 1.40

This script takes an IGES file containing a set of points, imports them into a 3D sketch and adds a bspline through them. For example it can be used with scanning data from a Romer arm. It can easily be adapted to manipulate the data (for example splitting it up, rotation, scaling) before importing.

# imports points from an IGES file into a 3D sketch
# and creates a bspline through the points
# requires wizoscript 1.40 and later
 
# specify which libraries we are going to use
import re
 
# 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 = []
 
# 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'))
 
    # add to list of points
    points.extend([x, y, z])
 
# finished with IGES file
f.close()
 
# show number of points found
print "Found %d points" % (len(points) / 3)
 
print "Creating 3D Sketch. This could take a few minutes..."
 
# create part
MyPart = Part("My Part")
# add 3D sketch
PointSketch = MyPart.Add3DSketch("Point Sketch")
# create bspline in 3D sketch using points
PointSketch.AddBspline(points)