-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathcutLine.py
123 lines (114 loc) · 3.91 KB
/
cutLine.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oProject = oDesktop.GetActiveProject()
oDesign = oProject.GetActiveDesign()
oEditor = oDesign.SetActiveEditor("3D Modeler")
unit=oEditor.GetModelUnits()
def func(edge):
p0, p1=edge
x0, y0, z0=map(float,p0)
x1, y1, z1=map(float,p1)
p=((x0+x1)/2, (y0+y1)/2, (z0+z1)/2)
v=((x1-x0),(y1-y0),(z1-z0))
return (p,v)
def getAll():
objs=[]
totalobjects = oEditor.GetNumObjects()
for i in range(totalobjects):
objs.append(oEditor.GetObjectName(i))
return objs
edges=oEditor.GetSelections()
AddWarningMessage(str(edges))
edge_vertex=[oEditor.GetVertexIDsFromEdge(float(i[4:])) for i in edges]
vertex_location=[(oEditor.GetVertexPosition(i),oEditor.GetVertexPosition(j)) for i,j in edge_vertex]
for p, v in map(func, vertex_location):
old_name=oDesign.GetName()
oProject.CopyDesign(old_name)
oProject.Paste()
oDesign=oProject.GetActiveDesign()
new_name=oDesign.GetName()
oDesign=oProject.SetActiveDesign(old_name)
oEditor = oDesign.SetActiveEditor("3D Modeler")
oEditor.SetWCS(
[
"NAME:SetWCS Parameter",
"Working Coordinate System:=", "Global",
"RegionDepCSOk:=" , False
])
oEditor.CreateRelativeCS(
[
"NAME:RelativeCSParameters",
"Mode:=" , "Axis/Position",
"OriginX:=" , "{}{}".format(p[0],unit),
"OriginY:=" , "{}{}".format(p[1],unit),
"OriginZ:=" , "{}{}".format(p[2],unit),
"XAxisXvec:=" , "{}{}".format(v[0],unit),
"XAxisYvec:=" , "{}{}".format(v[1],unit),
"XAxisZvec:=" , "{}{}".format(v[2],unit),
"YAxisXvec:=" , "0mm",
"YAxisYvec:=" , "0mm",
"YAxisZvec:=" , "1mm"
],
[
"NAME:Attributes",
"Name:=" , "cutCS"
])
oEditor.Split(
[
"NAME:Selections",
"Selections:=" ,','.join(getAll()),
"NewPartsModelFlag:=" , "Model"
],
[
"NAME:SplitToParameters",
"SplitPlane:=" , "YZ",
"WhichSide:=" , "NegativeOnly",
"ToolType:=" , "PlaneTool",
"ToolEntityID:=" , -1,
"SplitCrossingObjectsOnly:=", False,
"DeleteInvalidObjects:=", True
])
#-------------------
oDesign=oProject.SetActiveDesign(new_name)
oEditor = oDesign.SetActiveEditor("3D Modeler")
oEditor.SetWCS(
[
"NAME:SetWCS Parameter",
"Working Coordinate System:=", "Global",
"RegionDepCSOk:=" , False
])
oEditor.CreateRelativeCS(
[
"NAME:RelativeCSParameters",
"Mode:=" , "Axis/Position",
"OriginX:=" , "{}{}".format(p[0],unit),
"OriginY:=" , "{}{}".format(p[1],unit),
"OriginZ:=" , "{}{}".format(p[2],unit),
"XAxisXvec:=" , "{}{}".format(v[0],unit),
"XAxisYvec:=" , "{}{}".format(v[1],unit),
"XAxisZvec:=" , "{}{}".format(v[2],unit),
"YAxisXvec:=" , "0mm",
"YAxisYvec:=" , "0mm",
"YAxisZvec:=" , "1mm"
],
[
"NAME:Attributes",
"Name:=" , "cutCS"
])
oEditor.Split(
[
"NAME:Selections",
"Selections:=" ,','.join(getAll()),
"NewPartsModelFlag:=" , "Model"
],
[
"NAME:SplitToParameters",
"SplitPlane:=" , "YZ",
"WhichSide:=" , "PositiveOnly",
"ToolType:=" , "PlaneTool",
"ToolEntityID:=" , -1,
"SplitCrossingObjectsOnly:=", False,
"DeleteInvalidObjects:=", True
])
#---------------------------------