Skip to content

Commit

Permalink
FEAT: Rescale property in model units (#5542)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys authored Dec 9, 2024
1 parent c86f8ef commit 4e678aa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/ansys/aedt/core/modeler/cad/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def __init__(self, app, is3d=True):
self._unclassified = []
self._all_object_names = []
self._model_units = None
self.rescale_model = False
self._object_names_to_ids = {}
self.objects = Objects(self, "o")
self.user_defined_components = Objects(self, "u")
Expand Down Expand Up @@ -423,11 +424,23 @@ def materials(self):
def model_units(self):
"""Model units as a string. For example, ``"mm"``.
This property allows you to get or set the model units. When setting the model units,
you can specify whether to rescale the model by adjusting the ``rescale_model`` attribute.
References
----------
>>> oEditor.GetModelUnits
>>> oEditor.SetModelUnits
Examples
--------
>>> from ansys.aedt.core import hfss
>>> hfss = Hfss()
>>> hfss.modeler.model_units = "cm"
>>> hfss.modeler.rescale_model = True
>>> hfss.modeler.model_units = "mm"
"""
if not self._model_units:
self._model_units = self.oeditor.GetModelUnits()
Expand All @@ -436,7 +449,7 @@ def model_units(self):
@model_units.setter
def model_units(self, units):
assert units in AEDT_UNITS["Length"], f"Invalid units string {units}."
self.oeditor.SetModelUnits(["NAME:Units Parameter", "Units:=", units, "Rescale:=", False])
self.oeditor.SetModelUnits(["NAME:Units Parameter", "Units:=", units, "Rescale:=", self.rescale_model])
self._model_units = units

@property
Expand Down
8 changes: 8 additions & 0 deletions tests/system/general/test_07_Object3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,3 +768,11 @@ def test_20_simplify_objects(self):
)
assert not self.aedtapp.modeler.simplify_objects(assignment=None)
assert not self.aedtapp.modeler.simplify_objects(assignment=1)

def test_30_rescale(self):
self.aedtapp.modeler.model_units = "meter"
box1 = self.aedtapp.modeler.create_box([0, 0, 0], [5, 10, 2], material="Copper")
assert box1.mass == 893300.0
self.aedtapp.modeler.rescale_model = True
self.aedtapp.modeler.model_units = "mm"
assert round(box1.mass, 5) == 0.00089

0 comments on commit 4e678aa

Please sign in to comment.