Page 1 of 1

getComponentList or getComponentsList

Posted: Sat May 11, 2024 9:48 am
by hkimpara
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

Re: getComponentList or getComponentsList

Posted: Sat May 11, 2024 10:20 am
by tkuchida
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).

Re: getComponentList or getComponentsList

Posted: Mon May 13, 2024 8:30 am
by hkimpara
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