@@ -46,16 +46,16 @@ def display_image(image_name):
46
46
# Configure graphics for image export
47
47
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48
48
49
- ExtAPI . Graphics .Camera .SetSpecificViewOrientation (ViewOrientationType .Iso )
50
- ExtAPI . Graphics .Camera .SetFit ()
49
+ Graphics .Camera .SetSpecificViewOrientation (ViewOrientationType .Iso )
50
+ Graphics .Camera .SetFit ()
51
51
image_export_format = GraphicsImageExportFormat .PNG
52
52
settings_720p = Ansys .Mechanical .Graphics .GraphicsImageExportSettings ()
53
53
settings_720p .Resolution = GraphicsResolutionType .EnhancedResolution
54
54
settings_720p .Background = GraphicsBackgroundType .White
55
55
settings_720p .Width = 1280
56
56
settings_720p .Height = 720
57
57
settings_720p .CurrentGraphicsDisplay = False
58
- ExtAPI . Graphics .Camera .Rotate (180 , CameraAxisType .ScreenY )
58
+ Graphics .Camera .Rotate (180 , CameraAxisType .ScreenY )
59
59
60
60
# %%
61
61
# Download and import geometry
@@ -86,6 +86,7 @@ def display_image(image_name):
86
86
87
87
app .plot ()
88
88
89
+
89
90
# %%
90
91
# Download and import material
91
92
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -101,7 +102,7 @@ def display_image(image_name):
101
102
# %%
102
103
# Import materials
103
104
104
- MAT = ExtAPI . DataModel . Project . Model .Materials
105
+ MAT = Model .Materials
105
106
MAT .Import (mat_Copper_file_path )
106
107
MAT .Import (mat_Steel_file_path )
107
108
@@ -127,68 +128,48 @@ def display_image(image_name):
127
128
# %%
128
129
# Store all main tree nodes as variables
129
130
130
- MODEL = ExtAPI . DataModel . Project . Model
131
- GEOM = ExtAPI . DataModel . Project . Model .Geometry
132
- CONN_GRP = ExtAPI . DataModel . Project . Model .Connections
133
- CS_GRP = ExtAPI . DataModel . Project . Model .CoordinateSystems
134
- MSH = ExtAPI . DataModel . Project . Model .Mesh
135
- NS_GRP = ExtAPI . DataModel . Project . Model .NamedSelections
131
+ MODEL = Model
132
+ GEOM = Model .Geometry
133
+ CONN_GRP = Model .Connections
134
+ CS_GRP = Model .CoordinateSystems
135
+ MSH = Model .Mesh
136
+ NS_GRP = Model .NamedSelections
136
137
137
138
# %%
138
139
# Store named selections
139
140
140
- block3_block2_cont_NS = [
141
- x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "block3_block2_cont"
142
- ][0 ]
143
- block3_block2_targ_NS = [
144
- x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "block3_block2_targ"
145
- ][0 ]
146
- shank_block3_targ_NS = [
147
- x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "shank_block3_targ"
148
- ][0 ]
149
- shank_block3_cont_NS = [
150
- x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "shank_block3_cont"
151
- ][0 ]
152
- block1_washer_cont_NS = [
153
- x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "block1_washer_cont"
154
- ][0 ]
155
- block1_washer_targ_NS = [
156
- x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "block1_washer_targ"
157
- ][0 ]
158
- washer_bolt_cont_NS = [
159
- x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "washer_bolt_cont"
160
- ][0 ]
161
- washer_bolt_targ_NS = [
162
- x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "washer_bolt_targ"
163
- ][0 ]
164
- shank_bolt_targ_NS = [
165
- x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "shank_bolt_targ"
166
- ][0 ]
167
- shank_bolt_cont_NS = [
168
- x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "shank_bolt_cont"
169
- ][0 ]
170
- block2_block1_cont_NS = [
171
- x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "block2_block1_cont"
172
- ][0 ]
173
- block2_block1_targ_NS = [
174
- x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "block2_block1_targ"
175
- ][0 ]
176
- all_bodies = [x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "all_bodies" ][0 ]
177
- bodies_5 = [x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "bodies_5" ][0 ]
178
- shank = [x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "shank" ][0 ]
179
- shank_face = [x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "shank_face" ][0 ]
180
- shank_face2 = [x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "shank_face2" ][
141
+ block3_block2_cont_NS = [x for x in Tree .AllObjects if x .Name == "block3_block2_cont" ][
142
+ 0
143
+ ]
144
+ block3_block2_targ_NS = [x for x in Tree .AllObjects if x .Name == "block3_block2_targ" ][
145
+ 0
146
+ ]
147
+ shank_block3_targ_NS = [x for x in Tree .AllObjects if x .Name == "shank_block3_targ" ][0 ]
148
+ shank_block3_cont_NS = [x for x in Tree .AllObjects if x .Name == "shank_block3_cont" ][0 ]
149
+ block1_washer_cont_NS = [x for x in Tree .AllObjects if x .Name == "block1_washer_cont" ][
150
+ 0
151
+ ]
152
+ block1_washer_targ_NS = [x for x in Tree .AllObjects if x .Name == "block1_washer_targ" ][
181
153
0
182
154
]
183
- bottom_surface = [
184
- x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "bottom_surface"
185
- ][0 ]
186
- block2_surface = [
187
- x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "block2_surface"
188
- ][0 ]
189
- shank_surface = [
190
- x for x in ExtAPI .DataModel .Tree .AllObjects if x .Name == "shank_surface"
191
- ][0 ]
155
+ washer_bolt_cont_NS = [x for x in Tree .AllObjects if x .Name == "washer_bolt_cont" ][0 ]
156
+ washer_bolt_targ_NS = [x for x in Tree .AllObjects if x .Name == "washer_bolt_targ" ][0 ]
157
+ shank_bolt_targ_NS = [x for x in Tree .AllObjects if x .Name == "shank_bolt_targ" ][0 ]
158
+ shank_bolt_cont_NS = [x for x in Tree .AllObjects if x .Name == "shank_bolt_cont" ][0 ]
159
+ block2_block1_cont_NS = [x for x in Tree .AllObjects if x .Name == "block2_block1_cont" ][
160
+ 0
161
+ ]
162
+ block2_block1_targ_NS = [x for x in Tree .AllObjects if x .Name == "block2_block1_targ" ][
163
+ 0
164
+ ]
165
+ all_bodies = [x for x in Tree .AllObjects if x .Name == "all_bodies" ][0 ]
166
+ bodies_5 = [x for x in Tree .AllObjects if x .Name == "bodies_5" ][0 ]
167
+ shank = [x for x in Tree .AllObjects if x .Name == "shank" ][0 ]
168
+ shank_face = [x for x in Tree .AllObjects if x .Name == "shank_face" ][0 ]
169
+ shank_face2 = [x for x in Tree .AllObjects if x .Name == "shank_face2" ][0 ]
170
+ bottom_surface = [x for x in Tree .AllObjects if x .Name == "bottom_surface" ][0 ]
171
+ block2_surface = [x for x in Tree .AllObjects if x .Name == "block2_surface" ][0 ]
172
+ shank_surface = [x for x in Tree .AllObjects if x .Name == "shank_surface" ][0 ]
192
173
193
174
# %%
194
175
# Assign material to bodies
@@ -215,25 +196,22 @@ def display_image(image_name):
215
196
# Define coordinate system
216
197
# ~~~~~~~~~~~~~~~~~~~~~~~~~
217
198
218
- coordinate_systems_17 = Model .CoordinateSystems
219
- coordinate_system_93 = coordinate_systems_17 .AddCoordinateSystem ()
220
- coordinate_system_93 .OriginDefineBy = CoordinateSystemAlignmentType .Fixed
221
- coordinate_system_93 .OriginX = Quantity (- 195 , "mm" )
222
- coordinate_system_93 .OriginY = Quantity (100 , "mm" )
223
- coordinate_system_93 .OriginZ = Quantity (50 , "mm" )
224
- coordinate_system_93 .PrimaryAxis = CoordinateSystemAxisType .PositiveZAxis
199
+ coordinate_system = CS_GRP .AddCoordinateSystem ()
200
+ coordinate_system .OriginDefineBy = CoordinateSystemAlignmentType .Fixed
201
+ coordinate_system .OriginX = Quantity (- 195 , "mm" )
202
+ coordinate_system .OriginY = Quantity (100 , "mm" )
203
+ coordinate_system .OriginZ = Quantity (50 , "mm" )
204
+ coordinate_system .PrimaryAxis = CoordinateSystemAxisType .PositiveZAxis
225
205
226
206
# %%
227
207
# Define Contacts
228
208
# ~~~~~~~~~~~~~~~
229
209
# Change contact settings
230
210
231
- connections = ExtAPI .DataModel .Project .Model .Connections
232
-
233
211
# %%
234
212
# Delete existing contacts
235
213
236
- for connection in connections .Children :
214
+ for connection in CONN_GRP .Children :
237
215
if connection .DataModelObjectCategory == DataModelObjectCategory .ConnectionGroup :
238
216
connection .Delete ()
239
217
@@ -333,10 +311,10 @@ def display_image(image_name):
333
311
Sweep_Method .TargetLocation = shank_face2
334
312
335
313
MSH .Activate ()
336
- ExtAPI . Graphics . Camera . SetFit ()
337
- ExtAPI . Graphics . ExportImage (
338
- os . path . join ( cwd , "mesh.png" ), image_export_format , settings_720p
339
- )
314
+ MSH . GenerateMesh ()
315
+
316
+ Graphics . Camera . SetFit ()
317
+ Graphics . ExportImage ( os . path . join ( cwd , "mesh.png" ), image_export_format , settings_720p )
340
318
display_image ("mesh.png" )
341
319
342
320
# %%
@@ -407,7 +385,7 @@ def display_image(image_name):
407
385
Bolt_Pretension .SetDefineBy (4 , BoltLoadDefineBy .Lock )
408
386
409
387
Tree .Activate ([Bolt_Pretension ])
410
- ExtAPI . Graphics .ExportImage (
388
+ Graphics .ExportImage (
411
389
os .path .join (cwd , "loads_and_boundaryconditions.png" ),
412
390
image_export_format ,
413
391
settings_720p ,
@@ -458,8 +436,8 @@ def display_image(image_name):
458
436
# Total deformation
459
437
460
438
Tree .Activate ([Total_Deformation ])
461
- ExtAPI . Graphics .Camera .SetFit ()
462
- ExtAPI . Graphics .ExportImage (
439
+ Graphics .Camera .SetFit ()
440
+ Graphics .ExportImage (
463
441
os .path .join (cwd , "total_deformation.png" ), image_export_format , settings_720p
464
442
)
465
443
display_image ("total_deformation.png" )
@@ -468,8 +446,8 @@ def display_image(image_name):
468
446
# Equivalent stress on all bodies
469
447
470
448
Tree .Activate ([Equivalent_stress_1 ])
471
- ExtAPI . Graphics .Camera .SetFit ()
472
- ExtAPI . Graphics .ExportImage (
449
+ Graphics .Camera .SetFit ()
450
+ Graphics .ExportImage (
473
451
os .path .join (cwd , "equivalent_stress_total.png" ), image_export_format , settings_720p
474
452
)
475
453
display_image ("equivalent_stress_total.png" )
@@ -478,8 +456,8 @@ def display_image(image_name):
478
456
# Equivalent stress on shank
479
457
480
458
Tree .Activate ([Equivalent_stress_2 ])
481
- ExtAPI . Graphics .Camera .SetFit ()
482
- ExtAPI . Graphics .ExportImage (
459
+ Graphics .Camera .SetFit ()
460
+ Graphics .ExportImage (
483
461
os .path .join (cwd , "equivalent_stress_shank.png" ), image_export_format , settings_720p
484
462
)
485
463
display_image ("equivalent_stress_shank.png" )
@@ -489,7 +467,7 @@ def display_image(image_name):
489
467
490
468
Post_Contact_Tool_status = Post_Contact_Tool .Children [0 ]
491
469
Tree .Activate ([Post_Contact_Tool_status ])
492
- ExtAPI . Graphics .Camera .SetFit ()
470
+ Graphics .Camera .SetFit ()
493
471
animation_export_format = (
494
472
Ansys .Mechanical .DataModel .Enums .GraphicsAnimationExportFormat .GIF
495
473
)
@@ -521,7 +499,7 @@ def update(frame):
521
499
# Project tree
522
500
# ~~~~~~~~~~~~
523
501
524
- app .print_tree (DataModel . Project )
502
+ app .print_tree ()
525
503
526
504
# %%
527
505
# Cleanup
0 commit comments