Page 1 of 1

Accessing ThelenMuscle2003 through model class tree

Posted: Wed Mar 06, 2013 8:21 am
by acsantago
I am attempting to access properties of a specific muscle type through the model tree using the Matlab API interface. However, I am unsure how to go from the Muscle class to the ThelenMuscle2003 class. ie

import org.opensim.modeling.*
modelName = Test.osim;
Model = model(modelName);
MuscleSet = Model.getMuscles();
Muscle1 = MuscleSet.get(0);
activationTimeConstant = Muscle1.getActivationTimeConstant();


When I run the line:
activationTimeConstant = Muscle1.getActivationTimeConstant();
I receive the following error:
No appropriate method, property, or field getActivationTimeConstant for class org.opensim.modeling.Muscle

This makes sense considering the muscle class does not have access to the that function. However, I would like to have access to that function. Is there a way to traverse the model tree to obtain access to that class instance?

Re: Accessing ThelenMuscle2003 through model class tree

Posted: Fri Mar 08, 2013 10:13 am
by aymanh
Hi Anthony,

You need to downcast to the correct type that has the methods available using the syntax:

Code: Select all

Thelen2003Muscle.safeDowncase(Muscle1)
The result of the call will have the type Thelen2003Muscle and so its full set of methods will be available.

Hope this helps,
-Ayman

Re: Accessing ThelenMuscle2003 through model class tree

Posted: Mon Apr 28, 2014 9:19 am
by dhume878
I ran into this same problem and the syntax was a bit different than Ayman suggested below, but thank you very much for pointing me in the correct direction.

Code: Select all

Muscle1 = Thelen2003Muscle.safeDownCast(Muscle1);