Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
-
Hide Kimpara
- Posts: 135
- Joined: Mon Sep 19, 2016 5:12 am
Post
by Hide Kimpara » Sat May 11, 2024 9:48 am
Dear experts,
I have a trouble in calling component name list from Model class with Python and OpenSim 4.5.
My osim model has CoordinateActuator under components branch. In Python, Model class indicates method candidates as getComponentsList. So, I tried to write as below:
Code: Select all
model.getComponentsList('CoordinateActuator')
Then following message comes:
*** TypeError: getComponentsList() takes 1 positional argument but 2 were given
Api_docs (doxygen) says getComponentList existing but it's not getComponent"
s"List.
How can we call the registered names of CoordinateActuator under components branch?
Best regards,
Hide
Tags:
-
Thomas Uchida
- Posts: 1789
- Joined: Wed May 16, 2012 11:40 am
Post
by Thomas Uchida » Sat May 11, 2024 10:20 am
The getComponentsList() method does not take an argument; it returns a list of all components and does not downcast. Here is an example use case (from test_access_subcomponents.py):
Code: Select all
num_components = 0
for comp in model.getComponentsList():
num_components += 1
There do not seem to be Python bindings for the templated version with the singular "ComponentList" (e.g., "model.getComponentList<Muscle>()" in C++). If you wanted to find all the components of type CoordinateActuator in Python, you could use the iterator above and first check the component's concrete class name (see Component::getConcreteClassName() here:
https://simtk.org/api_docs/opensim/api_ ... 3ff60dd7e8).
-
Hide Kimpara
- Posts: 135
- Joined: Mon Sep 19, 2016 5:12 am
Post
by Hide Kimpara » Mon May 13, 2024 8:30 am
Hi, Tom,
Thank you for your suggestion and introducing an example to break down the ComponentsList.
Now I can pickup the CoordinateActuator as following.
Code: Select all
comps = model.getComponentsList()
for comp in comps:
if 'CoordinateActuator' in comp.getClassName():
print(comp.getName())
Best,
Hide