Browsed by
Tag: point

Slice a Part

Slice a Part

Compatible with WizoScript versions: 1.95

Slices a part at a plane called “Slice”

# open part
P = Part(r"P:\temp\GDForum", "Test")
 
# get bounding box of part - eight points, one for each corner
# of the bounding box
Bounds = P.GetBoundingBox()
 
# get the plane that the part will be sliced on
SlicePlane = P.GetPlane("Slice")
 
# create a sketch on the slicing plane
S = P.AddSketch("SliceSketch", SlicePlane)
 
# empty list
Proj = []
 
# for each corner of the part bounding box, map that 3D point into
# a 2D point on the sketch
# this doesn't create the points in the sketch, but is only a mathematical
# operation
for i in range(0, 8):
  Proj.append(S.GlobaltoPoint(Bounds[i][0], Bounds[i][1], Bounds[i][2]))
 
# go through the eight 2D points and find the maximum and minimum
# X and Y values
MaxX = Proj[0][0]
for i in range (0, 8):
  if Proj[i][0] >= MaxX :
    MaxX = Proj[i][0]
 
MaxY = Proj[0][1]
for i in range (0, 8):
  if Proj[i][1] >= MaxY :
    MaxY = Proj[i][1]
 
MinX = Proj[0][0]
for i in range (0, 8):
  if Proj[i][0] < MinX :
    MinX = Proj[i][0]
 
MinY = Proj[0][1]
for i in range (0, 8):
  if Proj[i][1] < MinY :
    MinY = Proj[i][1]
 
# draw a rectangle on the sketch which will cover the entire part when viewed
# perpendicular to the slicing plane
S.AddRectangle(MinX, MinY, MaxX, MaxY, False)
 
# cut the part using the rectangle
P.AddExtrudeCut("Cut", S, 100, False)
Reference Geometry

Reference Geometry

Compatible with WizoScript versions: 1.40

A short example showing how to create reference planes, axes and points.

# demonstrates creating reference geometry
 
# create a new part and get the xy plane
MyPart = Part("My Part")
XYPlane = MyPart.GetPlane("XY-Plane")
 
# create planes 100mm above and below the xy plane
TopPlane = MyPart.AddPlane("Top Plane", XYPlane, 100.0)
BottomPlane = MyPart.AddPlane("Bottom Plane", XYPlane, -100.0)
 
# add reference points to bottom plane
Ref1 = MyPart.AddPoint("Ref 1", 50.0, 50.0, -100.0)
Ref2 = MyPart.AddPoint("Ref 2", 50.0, -50.0, -100.0)
Ref3 = MyPart.AddPoint("Ref 3", -50.0, -50.0, -100.0)
Ref4 = MyPart.AddPoint("Ref 4", -50.0, 50.0, -100.0)
 
# add reference axes from points on bottom plane to center of top plane
Axis1 = MyPart.AddAxis("Axis 1", [50.0, 50.0, -100.0], [0.0, 0.0, 100.0])
Axis2 = MyPart.AddAxis("Axis 2", [50.0, -50.0, -100.0], [0.0, 0.0, 100.0])
Axis3 = MyPart.AddAxis("Axis 3", [-50.0, -50.0, -100.0], [0.0, 0.0, 100.0])
Axis4 = MyPart.AddAxis("Axis 4", [-50.0, 50.0, -100.0], [0.0, 0.0, 100.0])
Importer for IGES Point Files with Splitter

Importer for IGES Point Files with Splitter

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)