Skip to content

Unable to set script parameters using Quantity from ansys.units #2451

@ThomasS-SS

Description

@ThomasS-SS

🔍 Before submitting the issue

  • I have searched among the existing issues
  • I am using a Python virtual environment

🐞 Description of the bug

i am trying to set script parameters in a discovery file using Quantity from ansys.units and it does not work. I read in the docu that values should be int or float, but to me, beeing able to pass values as quantities including units feels just natural. Therefore, i labeled the issue as bug/problem.

I would also be interested in a workaround. It seems, that i have to pass a length as meter. Is that always the case? Can i somehow get the required dimension from the modeler or design?

Trying to use Quantity anyway i get:
CRITICAL - - logger - handle_exception - Uncaught exception
Traceback (most recent call last):
File "", line 1, in
exec(open("script.py").read())
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 22, in
File "<@beartype(ansys.geometry.core.designer.design.Design.set_parameter) at 0x256c41fc900>", line 13, in set_parameter
File "C:\Users\sld\pyEnvSimsam\Lib\site-packages\ansys\geometry\core\misc\checks.py", line 340, in wrapper
return method(self, *args, **kwargs)
File "C:\Users\sld\pyEnvSimsam\Lib\site-packages\ansys\geometry\core\designer\design.py", line 875, in set_parameter
response = self._grpc_client._services.driving_dimensions.set_parameter(
driving_dimension=dimension
)
File "C:\Users\sld\pyEnvSimsam\Lib\site-packages\ansys\geometry\core\errors.py", line 96, in wrapper
out = func(*args, **kwargs)
File "C:\Users\sld\pyEnvSimsam\Lib\site-packages\ansys\geometry\core_grpc_services\v0\driving_dimensions.py", line 76, in set_parameter
driving_dimension=from_driving_dimension_to_grpc_driving_dimension(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
kwargs["driving_dimension"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^
),
^
File "C:\Users\sld\pyEnvSimsam\Lib\site-packages\ansys\geometry\core_grpc_services\v0\conversions.py", line 1209, in from_driving_dimension_to_grpc_driving_dimension
return GRPCDrivingDimension(
id=driving_dimension.id,
...<2 lines>...
dimension_value=driving_dimension.dimension_value,
)
File "C:\Users\sld\pyEnvSimsam\Lib\site-packages\ansys\units\quantity.py", line 422, in float
raise ValueError(
"Cannot convert to a float as the Quantity is not dimensionless or a (solid) angle"
)
ValueError: Cannot convert to a float as the Quantity is not dimensionless or a (solid) angle

📝 Steps to reproduce

Please consider this script:

import ansys.geometry.core as pygeom
from ansys.units import Quantity

modeler = pygeom.launch_modeler_with_discovery(hidden=True)
modeler.open_file("Zylinder.dsco")
design = modeler.get_active_design()

# get all
dsc_pars = {}
for par in design.get_all_parameters():
print("parameter " + par.name)
dsc_pars[par.name] = par

# set some
radius = dsc_pars["radius"]
#radius.dimension_value = 0.01 # works and results in 10 mm in discovery
radius.dimension_value = Quantity(0.01, "m") # does not work

# communicate
for val in dsc_pars.values():
design.set_parameter(val)

and the embedded script of Zylinder.dsco:

# Python Script, API Version = V252
ClearAll()

# Kreis skizzieren
plane = Plane.PlaneXY
result = ViewHelper.SetSketchPlane(plane)
origin = Point2D.Create(MM(0), MM(0))
radius = Parameters.radius
result = SketchCircle.Create(origin, radius)

baseSel = SelectionPoint.Create(GetRootPart().DatumPlanes[0].Curves[0].GetChildren[ICurvePoint]()[0])
targetSel = SelectionPoint.Create(GetRootPart().DatumPlanes[0].GetChildren[IDatumPoint]()[0])

result = Constraint.CreateCoincident(baseSel, targetSel)
# EndBlock

# Volumenkörper aus Skizze bilden
mode = InteractionMode.Solid
result = ViewHelper.SetViewMode(mode, None)
# EndBlock

# 1 Fläche strecken
selection = FaceSelection.Create(GetRootPart().Bodies[0].Faces[0])
options = ExtrudeFaceOptions()
height = Parameters.height
result = ExtrudeFaces.Execute(selection, height, options)
# EndBlock

ans the script parameters:

Image

💻 Which operating system are you using?

Windows

📀 Which ANSYS version are you using?

25R2

🐍 Which Python version are you using?

3.13

📦 Installed packages

ansys-api-dbu==0.3.28
ansys-api-discovery==1.0.14
ansys-api-fluent==0.3.36
ansys-api-geometry==0.4.89
ansys-api-platform-instancemanagement==1.1.3
ansys-api-tools-filetransfer==0.1.2
ansys-fluent-core==0.35.0
ansys-fluent-visualization==0.22.1
ansys-geometry-core==0.14.1
ansys-platform-instancemanagement==1.1.2
ansys-tools-common==0.3.1
ansys-tools-filetransfer==0.1.1
ansys-tools-path==0.8.1
ansys-units==0.9.1
appdirs==1.4.4
art==6.5
beartype==0.22.5
certifi==2025.10.5
charset-normalizer==3.4.4
click==8.3.0
colorama==0.4.6
contourpy==1.3.3
cycler==0.12.1
defusedxml==0.7.1
Deprecated==1.2.18
dirsync==2.2.6
docker==7.1.0
flexcache==0.3
flexparser==0.4
fonttools==4.60.1
geomdl==5.4.0
googleapis-common-protos==1.71.0
grpcio==1.76.0
grpcio-health-checking==1.62.3
grpcio-status==1.62.3
idna==3.11
importlib_metadata==8.7.0
Jinja2==3.1.6
joblib==1.5.2
kiwisolver==1.4.9
MarkupSafe==3.0.3
matplotlib==3.10.7
nltk==3.9.2
numpy==2.3.4
packaging==25.0
pandas==2.3.3
pillow==12.0.0
Pint==0.25.2
platformdirs==4.5.0
pooch==1.8.2
protobuf==4.25.8
pyansys-tools-report==0.8.2
pyparsing==3.2.5
python-dateutil==2.9.0.post0
pytz==2025.2
pyvista==0.46.4
pywin32==311
PyYAML==6.0.3
regex==2025.10.23
requests==2.32.5
scipy==1.16.3
scooby==0.10.2
semver==3.0.4
setuptools==80.9.0
six==1.17.0
tqdm==4.67.1
typing_extensions==4.15.0
tzdata==2025.2
urllib3==2.5.0
vtk==9.5.2
wrapt==1.17.3
zipp==3.23.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions