This repository was archived by the owner on Jun 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlice-a-Part.py
More file actions
53 lines (41 loc) · 1.39 KB
/
Slice-a-Part.py
File metadata and controls
53 lines (41 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#https://help.alibre.com/articles/#!alibre-help-v28/slice-a-part
# 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)