Created
October 14, 2025 10:35
-
-
Save stephensmitchell/093dc7941df7b975c7bc21318065255a to your computer and use it in GitHub Desktop.
Slice a Part
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment