Page 1 of 1

Access model properties through python API; names of muscles and joints

Posted: Wed Aug 17, 2016 6:45 am
by neild
Hi, I am using the Gait2354_simbody.osim model for some work I am trying out.

Through the .osim file I know what the model components are called e.g. the given name of the muscles, through string assignments or bodies:

Code: Select all

				<Body name="femur_r">
					<mass>9.3014</mass>
					<mass_center> 0 -0.17 0</mass_center>
					<inertia_xx>0.1339</inertia_xx>
					<inertia_yy>0.0351</inertia_yy>
					<inertia_zz>0.1412</inertia_zz>
					<inertia_xy>0</inertia_xy>
					<inertia_xz>0</inertia_xz>
					<inertia_yz>0</inertia_yz>
Now I would like to access these strings through the python API. But I am not sure how to do this. Take the below:

Code: Select all

# Load model
model = osim.Model("gait2354_simbody.osim")

muscles = model.getMuscles()
muSize = muscles.getSize()
for i in range(muSize):
    print muscles.get(i)
It gets me all the 54 muscles, looping through them one by one, but just returns an object no specific identifier such as "glut_max3_r". How do I get access to these specifically?

Re: Access model properties through python API; names of muscles and joints

Posted: Wed Aug 17, 2016 7:02 am
by chrisdembia
Try this:

model.getMuscles().get("soleus_r")

Re: Access model properties through python API; names of muscles and joints

Posted: Wed Aug 17, 2016 7:08 am
by neild
No sure, I know you can do that; what I want is a list of all the muscles names as strings. I know I can access them one by one, by looking up the string name in the .osim file. I don't want to do this, I would just like to call a function that returns each muscle name to me. Something like:

Code: Select all

model.getMuscles().get(3).name()
>>>"glut_max3_r"

Re: Access model properties through python API; names of muscles and joints

Posted: Wed Aug 17, 2016 10:07 am
by chrisdembia
Each Object (including Muscle) has a method getName():

Code: Select all

model.getMuscles().get(3).getName()