Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: Add graphics and globals #790

Merged
merged 5 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/790.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FEAT: Add graphics and globals
21 changes: 13 additions & 8 deletions src/ansys/mechanical/core/embedding/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,19 @@

@property
def Tree(self):
"""Return the ExtAPI object."""
"""Return the Tree object."""
return GetterWrapper(self._app, lambda app: app.DataModel.Tree)

@property
def Model(self):
"""Return the ExtAPI object."""
"""Return the Model object."""
return GetterWrapper(self._app, lambda app: app.DataModel.Project.Model)

@property
def Graphics(self):
"""Return the Graphics object."""
return GetterWrapper(self._app, lambda app: app.ExtAPI.Graphics)

Check warning on line 282 in src/ansys/mechanical/core/embedding/app.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mechanical/core/embedding/app.py#L282

Added line #L282 was not covered by tests

@property
def readonly(self):
"""Return whether the Mechanical object is read-only."""
Expand Down Expand Up @@ -365,6 +370,12 @@
def _print_tree(self, node, max_lines, lines_count, indentation):
"""Recursively print till provided maximum lines limit.

Each object in the tree is expected to have the following attributes:
- Name: The name of the object.
- Suppressed : Print as suppressed, if object is suppressed.
- Children: Checks if object have children.
Each child node is expected to have the all these attributes.

Parameters
----------
lines_count: int, optional
Expand Down Expand Up @@ -397,12 +408,6 @@
"""
Print the hierarchical tree representation of the Mechanical project structure.

Each object in the tree is expected to have the following attributes:
- Name: The name of the object.
- Suppressed : Print as suppressed, if object is suppressed.
- Children: Checks if object have children.
Each child node is expected to have the all these attributes.

Parameters
----------
node: ExtAPI object
Expand Down
11 changes: 11 additions & 0 deletions src/ansys/mechanical/core/embedding/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def global_entry_points(app: "ansys.mechanical.core.App") -> typing.Dict:
vars["DataModel"] = app.DataModel
vars["Model"] = app.DataModel.Project.Model
vars["Tree"] = app.DataModel.Tree
vars["Graphics"] = app.ExtAPI.Graphics
return vars


Expand All @@ -51,8 +52,11 @@ def global_variables(app: "ansys.mechanical.core.App", enums: bool = False) -> t
clr.AddReference("Ansys.Mechanical.DataModel")
# from Ansys.ACT.Mechanical import Transaction
# When ansys-pythonnet issue #14 is fixed, uncomment above
from Ansys.ACT.Core.Math import Point2D, Point3D
from Ansys.ACT.Math import Vector3D
from Ansys.Core.Units import Quantity
from Ansys.Mechanical.DataModel import MechanicalEnums
from Ansys.Mechanical.Graphics import Point, SectionPlane

import System # isort: skip
import Ansys # isort: skip
Expand All @@ -62,6 +66,13 @@ def global_variables(app: "ansys.mechanical.core.App", enums: bool = False) -> t
vars["Ansys"] = Ansys
vars["Transaction"] = Transaction
vars["MechanicalEnums"] = MechanicalEnums
# Graphics
vars["Point"] = Point
vars["SectionPlane"] = SectionPlane
# Math
vars["Point2D"] = Point2D
vars["Point3D"] = Point3D
vars["Vector3D"] = Vector3D

if enums:
vars.update(get_all_enums())
Expand Down
6 changes: 6 additions & 0 deletions tests/embedding/test_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ def test_global_variables(embedded_app):
"DataModel",
"Model",
"Tree",
"Graphics",
"Quantity",
"System",
"Ansys",
"Transaction",
"MechanicalEnums",
"DataModelObjectCategory",
"Point",
"SectionPlane",
"Point2D",
"Point3D",
"Vector3D",
]
globals_dict = global_variables(embedded_app, True)
for attribute in attributes:
Expand Down
Loading