Slice a Part


Slices a part at a plane called "Slice".


*Edit line 2 in the script to reflect the directory path to your part and the part name.



# open part, replace with your own path
P = Part(r'C:\Users\Brian\Desktop\ScriptDir', 'New2')
 
# 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)





Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.