Skip to content

Commit 15e4fc2

Browse files
authored
Maint: New method of updating globals (#203)
1 parent 1d0a68a commit 15e4fc2

10 files changed

+17
-133
lines changed

examples/basic/bolt_pretension.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# Embed mechanical and set global variables
2828

2929
app = mech.App(version=241)
30-
globals().update(mech.global_variables(app, True))
30+
app.update_globals(globals())
3131
print(app)
3232

3333
cwd = os.path.join(os.getcwd(), "out")
@@ -525,21 +525,7 @@ def update(frame):
525525
# Project tree
526526
# ~~~~~~~~~~~~
527527

528-
529-
def print_tree(node, indentation=""):
530-
print(f"{indentation}├── {node.Name}")
531-
532-
if (
533-
hasattr(node, "Children")
534-
and node.Children is not None
535-
and node.Children.Count > 0
536-
):
537-
for child in node.Children:
538-
print_tree(child, indentation + "| ")
539-
540-
541-
root_node = DataModel.Project
542-
print_tree(root_node)
528+
app.print_tree(DataModel.Project)
543529

544530
# %%
545531
# Cleanup

examples/basic/fracture_analysis_contact_debonding.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# Embed mechanical and set global variables
2727

2828
app = mech.App(version=241)
29-
globals().update(mech.global_variables(app, True))
29+
app.update_globals(globals())
3030
print(app)
3131

3232
cwd = os.path.join(os.getcwd(), "out")
@@ -425,21 +425,7 @@ def write_file_contents_to_console(path):
425425
# Project tree
426426
# ~~~~~~~~~~~~
427427

428-
429-
def print_tree(node, indentation=""):
430-
print(f"{indentation}├── {node.Name}")
431-
432-
if (
433-
hasattr(node, "Children")
434-
and node.Children is not None
435-
and node.Children.Count > 0
436-
):
437-
for child in node.Children:
438-
print_tree(child, indentation + "| ")
439-
440-
441-
root_node = DataModel.Project
442-
print_tree(root_node)
428+
app.print_tree(DataModel.Project)
443429

444430
# %%
445431
# Cleanup

examples/basic/harmonic_acoustics.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -498,24 +498,7 @@ def write_file_contents_to_console(path):
498498
# Project tree
499499
# ~~~~~~~~~~~~
500500

501-
502-
def print_tree(node, indentation=""):
503-
if hasattr(node, "Suppressed") and node.Suppressed is True:
504-
print(f"{indentation}├── {node.Name} (Suppressed)")
505-
else:
506-
print(f"{indentation}├── {node.Name}")
507-
508-
if (
509-
hasattr(node, "Children")
510-
and node.Children is not None
511-
and node.Children.Count > 0
512-
):
513-
for child in node.Children:
514-
print_tree(child, indentation + "| ")
515-
516-
517-
root_node = DataModel.Project
518-
print_tree(root_node)
501+
app.print_tree(DataModel.Project)
519502

520503
# %%
521504
# Cleanup

examples/basic/modal_acoustics_analysis.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# Embed mechanical and set global variables
3333

3434
app = mech.App(version=241)
35-
globals().update(mech.global_variables(app, True))
35+
app.update_globals(globals())
3636
print(app)
3737

3838
cwd = os.path.join(os.getcwd(), "out")
@@ -523,21 +523,7 @@ def update(frame):
523523
# Project tree
524524
# ~~~~~~~~~~~~
525525

526-
527-
def print_tree(node, indentation=""):
528-
print(f"{indentation}├── {node.Name}")
529-
530-
if (
531-
hasattr(node, "Children")
532-
and node.Children is not None
533-
and node.Children.Count > 0
534-
):
535-
for child in node.Children:
536-
print_tree(child, indentation + "| ")
537-
538-
539-
root_node = DataModel.Project
540-
print_tree(root_node)
526+
app.print_tree(DataModel.Project)
541527

542528
# %%
543529
# Cleanup

examples/basic/steady_state_thermal_analysis.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# Embed mechanical and set global variables
3030

3131
app = mech.App(version=241)
32-
globals().update(mech.global_variables(app, True))
32+
app.update_globals(globals())
3333
print(app)
3434

3535
cwd = os.path.join(os.getcwd(), "out")
@@ -463,21 +463,7 @@ def write_file_contents_to_console(path):
463463
# Project tree
464464
# ~~~~~~~~~~~~
465465

466-
467-
def print_tree(node, indentation=""):
468-
print(f"{indentation}├── {node.Name}")
469-
470-
if (
471-
hasattr(node, "Children")
472-
and node.Children is not None
473-
and node.Children.Count > 0
474-
):
475-
for child in node.Children:
476-
print_tree(child, indentation + "| ")
477-
478-
479-
root_node = DataModel.Project
480-
print_tree(root_node)
466+
app.print_tree(DataModel.Project)
481467

482468
# %%
483469
# Cleanup

examples/basic/topology_optimization_cantilever_beam.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# Embed Mechanical and set global variables
2424

2525
app = mech.App(version=241)
26-
globals().update(mech.global_variables(app, True))
26+
app.update_globals(globals())
2727
print(app)
2828

2929

@@ -252,21 +252,7 @@ def write_file_contents_to_console(path):
252252
# Project tree
253253
# ~~~~~~~~~~~~
254254

255-
256-
def print_tree(node, indentation=""):
257-
print(f"{indentation}├── {node.Name}")
258-
259-
if (
260-
hasattr(node, "Children")
261-
and node.Children is not None
262-
and node.Children.Count > 0
263-
):
264-
for child in node.Children:
265-
print_tree(child, indentation + "| ")
266-
267-
268-
root_node = DataModel.Project
269-
print_tree(root_node)
255+
app.print_tree(DataModel.Project)
270256

271257
# %%
272258
# Cleanup

examples/basic/valve.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# Embed mechanical and set global variables
2424

2525
app = mech.App(version=241)
26-
globals().update(mech.global_variables(app, True))
26+
app.update_globals(globals())
2727
print(app)
2828

2929
cwd = os.path.join(os.getcwd(), "out")
@@ -252,21 +252,7 @@ def write_file_contents_to_console(path):
252252
# Project tree
253253
# ~~~~~~~~~~~~
254254

255-
256-
def print_tree(node, indentation=""):
257-
print(f"{indentation}├── {node.Name}")
258-
259-
if (
260-
hasattr(node, "Children")
261-
and node.Children is not None
262-
and node.Children.Count > 0
263-
):
264-
for child in node.Children:
265-
print_tree(child, indentation + "| ")
266-
267-
268-
root_node = DataModel.Project
269-
print_tree(root_node)
255+
app.print_tree(DataModel.Project)
270256

271257
# %%
272258
# Cleanup

examples/technology_showcase/Rotor_Blade_Inverse_solve.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
# Embed mechanical and set global variables
5959

6060
app = mech.App(version=241)
61-
globals().update(mech.global_variables(app, True))
61+
app.update_globals(globals())
6262
print(app)
6363

6464
cwd = os.path.join(os.getcwd(), "out")

examples/technology_showcase/conact_wear_simulation.py

+2-17
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
# Embed mechanical and set global variables
3939

4040
app = mech.App(version=241)
41-
globals().update(mech.global_variables(app, True))
41+
app.update_globals(globals())
4242
print(app)
4343

4444
cwd = os.path.join(os.getcwd(), "out")
@@ -381,22 +381,7 @@ def update(frame):
381381
# Project tree
382382
# ~~~~~~~~~~~~
383383

384-
385-
def print_tree(node, indentation=""):
386-
print(f"{indentation}├── {node.Name}")
387-
388-
if (
389-
hasattr(node, "Children")
390-
and node.Children is not None
391-
and node.Children.Count > 0
392-
):
393-
for child in node.Children:
394-
print_tree(child, indentation + "| ")
395-
396-
397-
root_node = DataModel.Project
398-
print_tree(root_node)
399-
384+
app.print_tree(DataModel.Project)
400385

401386
# %%
402387
# Cleanup

examples/technology_showcase/non_linear_analsis_rubber_boot_seal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# Embed mechanical and set global variables
3232

3333
app = mech.App(version=241)
34-
globals().update(mech.global_variables(app, True))
34+
app.update_globals(globals())
3535
print(app)
3636

3737
cwd = os.path.join(os.getcwd(), "out")

0 commit comments

Comments
 (0)