ansys/pyansys-geometry

design.named_selections is not updated after read_existing_design() call

Closed this issue ยท 3 comments

๐Ÿ” Before submitting the issue

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

๐Ÿž Description of the bug

If a design without Named Selections is opened it and then some Named Selections are created not with PyGeometry, they won't show in design.named_selections. This is expected behavior.
Running the command modeler.read_existing_design() to update the design, it correctly finds the created Named Selections.

image

Unfortunately, design.named_selections is still an empty list.

๐Ÿ“ Steps to reproduce

  1. Open a design without named selections
  2. Create a named selection in the application, without using PyGeometry.
  3. Run modeler.read_existing_design() and verify that returns the named selection.
  4. design.named_selections is still empty.

๐Ÿ’ป Which operating system are you using?

Windows

๐Ÿ“€ Which ANSYS version are you using?

Discovery 2024R1

๐Ÿ Which Python version are you using?

3.10

๐Ÿ“ฆ Installed packages

ansys-api-dbu==0.2.5
ansys-api-geometry==0.3.8
ansys-geometry-core==0.4.14
ansys-pythonnet==3.1.0rc3
ansys-tools-path==0.5.1
attrs==23.2.0
beartype==0.18.2
cachetools==5.3.3
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
click==8.1.7
clr-loader==0.2.6
colorama==0.4.6
contourpy==1.2.1
cycler==0.12.1
defusedxml==0.7.1
fonttools==4.50.0
fpdf2==2.7.8
google-api-core==2.18.0
google-api-python-client==2.125.0
google-auth==2.29.0
google-auth-httplib2==0.2.0
googleapis-common-protos==1.63.0
grpcio==1.62.1
grpcio-health-checking==1.62.1
httplib2==0.22.0
idna==3.6
jsonschema==4.21.1
jsonschema-specifications==2023.12.1
kiwisolver==1.4.5
matplotlib==3.8.4
numpy==1.26.4
packaging==24.0
pillow==10.3.0
Pint==0.23
platformdirs==4.2.0
plumbum==1.8.2
pooch==1.8.1
proto-plus==1.23.0
protobuf==4.25.3
psutil==5.9.8
pyaedt==0.8.7
pyasn1==0.6.0
pyasn1_modules==0.4.0
pycparser==2.22
pyedb==0.7.0
pyparsing==3.1.2
python-dateutil==2.9.0.post0
pytomlpp==1.0.13
pyvista==0.43.5
pywin32==306
referencing==0.34.0
requests==2.31.0
rpds-py==0.18.0
rpyc==6.0.0
rsa==4.9
scipy==1.13.0
scooby==0.9.2
six==1.16.0
typing_extensions==4.10.0
uritemplate==4.1.1
urllib3==2.2.1
vtk==9.3.0

@Alberto-DM can you share your script with us? Not just the final command you are running.

Also, I believe that you are not using the updated design.

modeler.read_existing_design returns a new Design object which should be the one you use. Consequently, your code should look something like this:

# Launch modeler
modeler = launch_modeler()

# Do whatever to have a Design on the service
design = modeler.create_design("MyDesign")
...

# After named selections have been created outside PyAnsys Geometry... update the design
design = modeler.read_existing_design()

The most critical part of this code is the last line. It is necessary that the output of read_existing_design object is stored under your old design object. Your previous design object is outdated after performing read_existing_design and you should update it yourself.

@RobPasMue I think you are right: I am not using the updated design.
I assumed that read_existing_design was updating the existing object design.

This is the script:

modeler = launch_modeler_with_discovery(product_version=version,hidden=non_graphical)
design = modeler.open_file(file_path=filename, upload_to_server=False)
groups = modeler.run_discovery_script_file(file_path=r"scripts\create_groups_by_color.py")
groups_dict = dict(groups)
modeler.read_existing_design()
ns = design.named_selections
bodies = design.bodies

Yep, precisely. That's the issue. You are not using the updated design. Whenever you call modeler.read_existing_design() remember to update the design object. =)

Closing this issue since solved