Skip to content

Commit

Permalink
FEAT: Get coordinate system (#5039)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Alex Pham <[email protected]>
  • Loading branch information
3 people authored Aug 13, 2024
1 parent 6f29994 commit ca17b80
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
15 changes: 15 additions & 0 deletions _unittest/test_02_3D_modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,18 +681,33 @@ def test_43c_set_as_working_object_cs(self):
def test_43_set_working_coordinate_system(self):
cs1 = self.aedtapp.modeler.create_coordinate_system(name="new1")
assert self.aedtapp.modeler.set_working_coordinate_system("Global")
assert self.aedtapp.modeler.get_working_coordinate_system() == "Global"

assert self.aedtapp.modeler.set_working_coordinate_system("new1")
assert self.aedtapp.modeler.get_working_coordinate_system() == "new1"

assert self.aedtapp.modeler.set_working_coordinate_system("Global")
assert self.aedtapp.modeler.get_working_coordinate_system() == "Global"

assert self.aedtapp.modeler.set_working_coordinate_system(cs1)
assert self.aedtapp.modeler.get_working_coordinate_system() == cs1.name

def test_43_set_working_face_coordinate_system(self):
box = self.aedtapp.modeler.create_box([0, 0, 0], [2, 2, 2])
face = box.faces[0]
fcs = self.aedtapp.modeler.create_face_coordinate_system(face, face, face.edges[1], name="new2")

assert self.aedtapp.modeler.set_working_coordinate_system("Global")
assert self.aedtapp.modeler.get_working_coordinate_system() == "Global"

assert self.aedtapp.modeler.set_working_coordinate_system("new2")
assert self.aedtapp.modeler.get_working_coordinate_system() == "new2"

assert self.aedtapp.modeler.set_working_coordinate_system("Global")
assert self.aedtapp.modeler.get_working_coordinate_system() == "Global"

assert self.aedtapp.modeler.set_working_coordinate_system(fcs)
assert self.aedtapp.modeler.get_working_coordinate_system() == fcs.name

def test_44_sweep_around_axis(self):
rect1 = self.aedtapp.modeler.create_rectangle(self.aedtapp.PLANE.YZ, [0, 0, 0], [20, 20], "rectangle_to_split")
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/hfss.py
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ def create_sbr_antenna(
self.logger.error("This native component only applies to a SBR+ solution.")
return False
if target_cs is None:
target_cs = self.modeler.oeditor.GetActiveCoordinateSystem()
target_cs = self.modeler.get_working_coordinate_system()
parameters_defaults = self.SBRAntennaDefaults.parameters[antenna_type].copy()
if use_current_source_representation and antenna_type in [
"Conical Horn",
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/icepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@ def create_parametric_heatsink_on_face(
name_map["NumColumnsPerSide"],
True,
)
cs = self.modeler.oeditor.GetActiveCoordinateSystem()
cs = self.modeler.get_working_coordinate_system()
cs_ymax = self.modeler.create_coordinate_system(
self.Position(0, name_map["HSHeight"] + "/2", 0),
mode="view",
Expand Down
17 changes: 17 additions & 0 deletions pyaedt/modeler/cad/Primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,23 @@ def set_working_coordinate_system(self, name):
)
return True

@pyaedt_function_handler()
def get_working_coordinate_system(self):
"""Get the active coordinate system.
Returns
-------
str
Name of the active coordinate system.
References
----------
>>> oEditor.GetActiveCoordinateSystem
"""

return self.oeditor.GetActiveCoordinateSystem()

@pyaedt_function_handler()
def invert_cs(self, coordinate_system, to_global=False):
"""Get the inverse translation and the conjugate quaternion of the input coordinate system.
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/modeler/cad/Primitives3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ def _create_reference_cs_from_3dcomp(self, assignment, password):
3d component.
"""
app = assignment.edit_definition(password=password)
wcs = app.modeler.oeditor.GetActiveCoordinateSystem()
wcs = app.modeler.get_working_coordinate_system()
if wcs != "Global":
temp_folder = os.path.join(
self._app.toolkit_directory, self._app.design_name, generate_unique_name("temp_folder")
Expand Down

0 comments on commit ca17b80

Please sign in to comment.