Page 1 of 1
How to use the getCoordinatesInMultibodyTreeOrder() function in Python
Posted: Sat Dec 07, 2024 6:31 am
by huhu
I'm trying to get the coordinates in multibody tree order (not CoordinateSet order).
coords = model.getCoordinatesInMultibodyTreeOrder()
type(coords[0])
opensim.simulation.ReferencePtrCoordinate
model.getCoordinateNamesInMultibodyTreeOrder()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[1], line 1
----> 1 model.getCoordinateNamesInMultibodyTreeOrder()
NameError: name 'model' is not defined
How to use the getCoordinatesInMultibodyTreeOrder() function and output the names of the coordinates in multibody tree order?
Re: How to use the getCoordinatesInMultibodyTreeOrder() function in Python
Posted: Sat Dec 07, 2024 9:55 am
by kernalnet
Hi,
getCoordinateNamesInMultibodyTreeOrder can be used instead:
Code: Select all
model.initSystem()
coordNames = model.getCoordinateNamesInMultibodyTreeOrder()
[coordNames.getElt(i) for i in range(coordNames.size())]
Hope this helps.
Re: How to use the getCoordinatesInMultibodyTreeOrder() function in Python
Posted: Sat Dec 07, 2024 6:28 pm
by huhu
Thank you for your reply, but it still doesn't seem to work. Please take a look at the following error. I am using OpenSim 4.5 installed via Conda.
opensim 4.5 py311np123 opensim-org
import opensim as osim
model = osim.Model("arm26.osim")
model.initSystem()
coordNames = model.getCoordinateNamesInMultibodyTreeOrder()
[coordNames.getElt(i) for i in range(coordNames.size())]
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[4], line 4
2 model = osim.Model("arm26.osim")
3 model.initSystem()
----> 4 coordNames = model.getCoordinateNamesInMultibodyTreeOrder()
5 [coordNames.getElt(i) for i in range(coordNames.size())]
AttributeError: 'Model' object has no attribute 'getCoordinateNamesInMultibodyTreeOrder'
Re: How to use the getCoordinatesInMultibodyTreeOrder() function in Python
Posted: Sun Dec 08, 2024 2:52 am
by kernalnet
Hi, it seems that this method has been introduced recently and doesn't exist in the official 4.5 release. Possible solutions:
1. You can wait for the next official release.
2. Try the latest artifact:
https://github.com/opensim-org/opensim- ... ldartifact
3. Use this alternative method:
Code: Select all
coordSet = model.getCoordinateSet()
test = [[c.getBodyIndex(), c.getMobilizerQIndex(), c.getName()] for c in coordSet]
multibodyTreeOrder = [i[2] for i in sorted(test)]
Hope this helps.
Re: How to use the getCoordinatesInMultibodyTreeOrder() function in Python
Posted: Sun Dec 08, 2024 6:32 pm
by huhu
Thank you very much, this solved my problem.
Re: How to use the getCoordinatesInMultibodyTreeOrder() function in Python
Posted: Mon Dec 09, 2024 10:43 am
by aymanh
Thanks Mohammadreza,
Indeed the function was introduced post 4.5 but should be available in 4.5.1 which is also available as a conda package.
Hope this helps,
-Ayman