ansys / pymechanical

Pythonic interface to Ansys Mechanical β„’
https://mechanical.docs.pyansys.com/
MIT License
36 stars 18 forks source link

Cannot add ids to SelectionInfo #93

Closed pmaroneh closed 1 year ago

pmaroneh commented 1 year ago

πŸ” Before submitting the issue

🐞 Description of the bug

The code below works fine in the GUI: # Assign material matAssignment = Model.Materials.AddMaterialAssignment() tempSel = ExtAPI.SelectionManager.CreateSelectionInfo(Ansys.ACT.Interfaces.Common.SelectionTypeEnum.GeometryEntities) bodies = [body for body in ExtAPI.DataModel.Project.Model.Geometry.GetChildren(Ansys.Mechanical.DataModel.Enums.DataModelObjectCategory.Body,True)] geobodies = [body.GetGeoBody() for body in bodies] tempSel.Ids = [geobody.Id for geobody in geobodies] matAssignment.Location = tempSel matAssignment.Material = "Structural Steel"

But in embedded mode, tempSel.Ids = [geobody.Id for geobody in geobodies] does not work and the following error is returned: image

The current workaround is to use tempSel.Ids.Add(id)

πŸ“ Steps to reproduce

See above.

πŸ’» Which operating system are you using?

Windows

🐍 Which Python version are you using?

3.7

πŸ“¦ Installed packages

ansys-api-platform-instancemanagement==1.0.0b3
-e git+https://github.com/pyansys/pymechanical.git@a7bb62749e64b43373fb4fa9b620cc642613d5ed#egg=ansys_mechanical_core
ansys-platform-instancemanagement==1.0.2
ansys-pythonnet==3.1.0rc1
anyio==3.6.2
appdirs==1.4.4
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
arrow==1.2.3
asttokens @ file:///opt/conda/conda-bld/asttokens_1646925590279/work
attrs==22.2.0
Babel==2.11.0
backcall @ file:///home/ktietz/src/ci/backcall_1611930011877/work
beautifulsoup4==4.11.1
bleach==5.0.1
cachetools==5.2.1
certifi @ file:///C:/b/abs_4f5wo627a3/croots/recipe/certifi_1663615677642/work/certifi
cffi==1.15.1
chardet==5.1.0
charset-normalizer==3.0.1
cloudpickle @ file:///tmp/build/80754af9/cloudpickle_1632508026186/work
clr-loader==0.2.5
colorama==0.4.6
debugpy @ file:///C:/ci/debugpy_1637091961445/work
decorator @ file:///opt/conda/conda-bld/decorator_1643638310831/work
defusedxml==0.7.1
distlib==0.3.6
docutils==0.19
entrypoints==0.4
executing @ file:///opt/conda/conda-bld/executing_1646925071911/work
fastjsonschema==2.16.2
filelock==3.9.0
flit==3.8.0
flit_core==3.8.0
fqdn==1.5.1
googleapis-common-protos==1.56.4
grpcio==1.49.1
idna==3.4
importlib-metadata==5.0.0
ipykernel @ file:///C:/b/abs_21ykzkm7y_/croots/recipe/ipykernel_1662361803478/work
ipython @ file:///C:/ci/ipython_1657634415474/work
ipython-genutils==0.2.0
isoduration==20.11.0
jedi @ file:///C:/ci/jedi_1644315428289/work
Jinja2==3.1.2
json5==0.9.11
jsonpointer==2.3
jsonschema==4.17.3
jupyter-events==0.6.3
jupyter_client==7.4.9
jupyter_core==5.1.3
jupyter_server==2.1.0
jupyter_server_terminals==0.4.4
jupyterlab==3.5.2
jupyterlab-pygments==0.2.2
jupyterlab_server==2.19.0
MarkupSafe==2.1.1
matplotlib-inline @ file:///C:/ci/matplotlib-inline_1661915841596/work
mistune==2.0.4
nbclassic==0.4.8
nbclient==0.7.2
nbconvert==7.2.8
nbformat==5.7.3
nest-asyncio @ file:///C:/ci/nest-asyncio_1649829929390/work
notebook==6.5.2
notebook_shim==0.2.2
packaging==23.0
pandocfilters==1.5.0
parso @ file:///opt/conda/conda-bld/parso_1641458642106/work
pickleshare @ file:///tmp/build/80754af9/pickleshare_1606932040724/work
platformdirs==2.6.2
pluggy==1.0.0
prometheus-client==0.15.0
prompt-toolkit @ file:///tmp/build/80754af9/prompt-toolkit_1633440160888/work
protobuf==3.20.3
protoc-gen-swagger==0.1.0
psutil @ file:///C:/Windows/Temp/abs_b2c2fd7f-9fd5-4756-95ea-8aed74d0039flsd9qufz/croots/recipe/psutil_1656431277748/work
pure-eval @ file:///opt/conda/conda-bld/pure_eval_1646925070566/work
pycparser==2.21
Pygments @ file:///opt/conda/conda-bld/pygments_1644249106324/work
pyparsing @ file:///C:/Users/BUILDE~1/AppData/Local/Temp/abs_7f_7lba6rl/croots/recipe/pyparsing_1661452540662/work
pyproject_api==1.4.0
pyrsistent==0.19.3
python-dateutil @ file:///tmp/build/80754af9/python-dateutil_1626374649649/work
python-json-logger==2.0.4
pytz==2022.7.1
pywin32==302
pywinpty==2.0.10
PyYAML==6.0
pyzmq==25.0.0
requests==2.28.2
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
Send2Trash==1.8.0
six @ file:///tmp/build/80754af9/six_1644875935023/work
sniffio==1.3.0
soupsieve==2.3.2.post1
spyder-kernels @ file:///C:/ci/spyder-kernels_1634237096710/work
stack-data @ file:///opt/conda/conda-bld/stack_data_1646927590127/work
terminado==0.17.1
tinycss2==1.2.1
tomli==2.0.1
tomli_w==1.0.0
tornado @ file:///C:/ci/tornado_1662458743919/work
tox==4.3.1
tqdm==4.64.1
traitlets==5.8.1
uri-template==1.2.0
urllib3==1.26.14
virtualenv==20.17.1
wcwidth @ file:///Users/ktietz/demo/mc3/conda-bld/wcwidth_1629357192024/work
webcolors==1.12
webencodings==0.5.1
websocket-client==1.4.2
wincertstore==0.2
zipp==3.8.1
koubaa commented 1 year ago

workaround:

ids = System.Collections.Generic.List[System.Int32]()
[ids.Add(item) for item in input]
tempSel.Ids = ids
koubaa commented 1 year ago

@pmaroneh This might actually already be fixed in the latest commit of pymechanical. Could you try a git pull?

pmaroneh commented 1 year ago

I think I have the latest code (?): image.

Your workaround also works fine, thanks. matAssignment = Model.Materials.AddMaterialAssignment() tempSel = ExtAPI.SelectionManager.CreateSelectionInfo(Ansys.ACT.Interfaces.Common.SelectionTypeEnum.GeometryEntities) bodies = [body for body in ExtAPI.DataModel.Project.Model.Geometry.GetChildren(Ansys.Mechanical.DataModel.Enums.DataModelObjectCategory.Body,True)] geobodies = [body.GetGeoBody() for body in bodies] ids = System.Collections.Generic.List[System.Int32]() [ids.Add(item.Id) for item in geobodies] tempSel.Ids = ids matAssignment.Location = tempSel matAssignment.Material = "Structural Steel"

koubaa commented 1 year ago

@pmaroneh are you sure that the version of pymechanical that is installed to your python environment is the latest one? It's not enough to simply pull the git repo to confirm it.

pmaroneh commented 1 year ago

I was now able to get v0.7dev3 and it is indeed fixed there. Many thanks.