-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathcreateRectangleSpiral.py
92 lines (82 loc) · 2.73 KB
/
createRectangleSpiral.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
86
87
88
89
90
91
92
import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oProject = oDesktop.GetActiveProject()
oDesign = oProject.GetActiveDesign()
oEditor = oDesign.SetActiveEditor("3D Modeler")
unit=oEditor.GetModelUnits()
def getpts(pts_list):
pts=[]
segs=[]
n=0
for x, y, z in pts_list:
_x, _y, _z = str(x)+unit, str(y)+unit, str(z)+unit
pts.append(["NAME:PLPoint","X:=", _x,"Y:=", _y,"Z:=", _z])
for i in range(len(pts)-1):
segs.append(["NAME:PLSegment","SegmentType:=","Line","StartIndex:=",i,"NoOfPoints:=",2])
return pts, segs
def create_polyline(pts_list, name):
pts, segs=getpts(pts_list)
oEditor.CreatePolyline(
[
"NAME:PolylineParameters",
"IsPolylineCovered:=" , True,
"IsPolylineClosed:=" , False,
["NAME:PolylinePoints"] + pts,
["NAME:PolylineSegments"] + segs,
[
"NAME:PolylineXSection",
"XSectionType:=" , "None",
"XSectionOrient:=" , "Auto",
"XSectionWidth:=" , "0mm",
"XSectionTopWidth:=" , "0mm",
"XSectionHeight:=" , "0mm",
"XSectionNumSegments:=" , "0",
"XSectionBendType:=" , "Corner"
]
],
[
"NAME:Attributes",
"Name:=" , name,
"Flags:=" , "",
"Color:=" , "(157 249 158)",
"Transparency:=" , 0,
"PartCoordinateSystem:=", "Global",
"UDMId:=" , "",
"MaterialValue:=" , "\"vacuum\"",
"SurfaceMaterialValue:=", "\"\"",
"SolveInside:=" , True,
"IsMaterialEditable:=" , True,
"UseMaterialAppearance:=", False,
"IsLightweight:=" , False
])
def createspiral(a, b, pitch, sw, st, N):
pts=[]
z=0
for x, y in [(-a, -b), (a, -b), (a, b), (-a, b)]*N:
pts.append((x, y, z))
z+=pitch/4
create_polyline(pts, 'trace1')
pts=[]
z=sw
for x, y in [(-a, -b), (a, -b), (a, b), (-a, b)]*N:
pts.append((x, y, z))
z+=pitch/4
create_polyline(pts, 'trace2')
oEditor.Connect(
[
"NAME:Selections",
"Selections:=" , 'trace1, trace2'
])
oEditor.ThickenSheet(
[
"NAME:Selections",
"Selections:=" , "trace1",
"NewPartsModelFlag:=" , "Model"
],
[
"NAME:SheetThickenParameters",
"Thickness:=" , str(-st)+unit,
"BothSides:=" , True
])
createspiral(3, 2, 1, 0.5, 0.1, 10)