-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfit_circle.py
85 lines (69 loc) · 2.71 KB
/
fit_circle.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
## fit circle with given radius from the imported GDS file
## to be used to remove small dotted connected features
## can be used to fit other shape by replacing the sketch fuction
def fitCircle(current_body, R):
selectionDesignFace = current_body.Faces[0]
selectionFace = FaceSelection.Create(selectionDesignFace)
# # Set Sketch Plane
result = ViewHelper.SetSketchPlane(selectionFace)
# # EndBlock
# # Sketch Circle
origin = Point2D.Create(MM(0), MM(0))
result = SketchCircle.Create(origin, MM(R))
# # EndBlock
def setInvisible(current_body):
# # Change Object Visibility
visibility = VisibilityType.Hide
inSelectedView = False
faceLevel = False
selectionDesignbody = current_body
selectionBody = BodySelection.Create(selectionDesignbody)
ViewHelper.SetObjectVisibility(selectionBody, visibility, inSelectedView, faceLevel)
# # EndBlock
def deleteBody(current_body):
# delete surface
selectionDesignbody = current_body
selectionBody = BodySelection.Create(selectionDesignbody)
result = Delete.Execute(selectionBody)
# # Solidify Sketch
mode = InteractionMode.Solid
result = ViewHelper.SetViewMode(mode)
# # EndBlock
def createCylinder(height):
# # Extrude 1 Face
selectionDesignFace = GetRootPart().Bodies[-1].Faces[0]
selection = FaceSelection.Create(selectionDesignFace)
options = ExtrudeFaceOptions()
options.ExtrudeType = ExtrudeType.Add
result = ExtrudeFaces.Execute(selection, MM(height), options)
# # EndBlock
def createCylinderAll(height):
# # Extrude all Faces
visible_faces = [body.Faces[0] for body in GetRootPart().Bodies]
selection = FaceSelection.Create(visible_faces)
options = ExtrudeFaceOptions()
options.ExtrudeType = ExtrudeType.Add
result = ExtrudeFaces.Execute(selection, MM(height), options)
# # Get the root part
part = GetRootPart()
print(part.GetName())
# Get the bodies directly under the root part
bodies = part.GetBodies()
# # ------------------set R and height of a cylinder----------------------
# # !! mimimum value of R should be larger than 0.03 or software will not generate anything
R = 0.031
height = 0.02
# # ----------------------------------------------------------------------
# # Loop through the bodies
for current_body in bodies:
fitCircle(current_body, R)
## choose to hide original surface, but need to move it before creating body
# setInvisible(current_body)
deleteBody(current_body)
## choose to pull the cylinder body one by one in the loop
# createCylinder(height)
# # choose to pull all the cylinder body all at once, may hang at large number
createCylinderAll(height)
Selection.Clear()
ViewHelper.ZoomToEntity()
# # EndBlock