Skip to content

Commit

Permalink
FEAT: Update object state for print_tree() (#1005)
Browse files Browse the repository at this point in the history
Co-authored-by: pyansys-ci-bot <[email protected]>
  • Loading branch information
dipinknair and pyansys-ci-bot authored Dec 20, 2024
1 parent 033053b commit 8a2f4f5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/1005.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update object state for `print_tree()`
31 changes: 20 additions & 11 deletions src/ansys/mechanical/core/embedding/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,15 @@ def _print_tree(self, node, max_lines, lines_count, indentation):
node_name = node.Name
if hasattr(node, "Suppressed") and node.Suppressed is True:
node_name += " (Suppressed)"
if hasattr(node, "ObjectState"):
if str(node.ObjectState) == "UnderDefined":
node_name += " (?)"
elif str(node.ObjectState) == "Solved" or str(node.ObjectState) == "FullyDefined":
node_name += " (✓)"
elif str(node.ObjectState) == "NotSolved" or str(node.ObjectState) == "Obsolete":
node_name += " (⚡︎)"
elif str(node.ObjectState) == "SolveFailed":
node_name += " (✕)"
print(f"{indentation}├── {node_name}")
lines_count += 1

Expand Down Expand Up @@ -545,24 +554,24 @@ def print_tree(self, node=None, max_lines=80, lines_count=0, indentation=""):
Examples
--------
>>> import ansys.mechanical.core as mech
>>> app = mech.App()
>>> from ansys.mechanical.core import App
>>> app = App()
>>> app.update_globals(globals())
>>> app.print_tree()
... ├── Project
... | ├── Model
... | | ├── Geometry Imports
... | | ├── Geometry
... | | ├── Materials
... | | ├── Coordinate Systems
... | | | ├── Global Coordinate System
... | | ├── Remote Points
... | | ├── Mesh
... | | ├── Geometry Imports (⚡︎)
... | | ├── Geometry (?)
... | | ├── Materials (✓)
... | | ├── Coordinate Systems (✓)
... | | | ├── Global Coordinate System (✓)
... | | ├── Remote Points (✓)
... | | ├── Mesh (?)
>>> app.print_tree(Model, 3)
... ├── Model
... | ├── Geometry Imports
... | ├── Geometry
... | ├── Geometry Imports (⚡︎)
... | ├── Geometry (?)
... ... truncating after 3 lines
>>> app.print_tree(max_lines=2)
Expand Down
7 changes: 7 additions & 0 deletions tests/embedding/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ def test_app_print_tree(embedded_app, capsys, assets):
with pytest.raises(AttributeError):
embedded_app.print_tree(DataModel)

Modal = Model.AddModalAnalysis()
Modal.Solution.Solve(True)
embedded_app.print_tree()
captured = capsys.readouterr()
printed_output = captured.out.strip()
assert all(symbol in printed_output for symbol in ["?", "⚡︎", "✕", "✓"])


@pytest.mark.embedding
def test_app_poster(embedded_app):
Expand Down

0 comments on commit 8a2f4f5

Please sign in to comment.