Page 1 of 1

Unable to safeDownCast to ConcreteClass

Posted: Tue May 18, 2021 7:52 pm
by djacobs
Working with model that uses ligaments from a plugin. I am unable to access the ligament properties via finding the appropriate ligament in the force set index and then using safe down cast. I am getting this error (included my check points to verify I was looking at the correct object, and the concrete class was correct):

Code: Select all

Unable to resolve the name Blankevoort1991Ligament.safeDownCast.

Error in newTare (line 62)
        currentLig = Blankevoort1991Ligament.safeDownCast(force);

To ensure I was using this properly, I used it the method on a non custom component, a Millard muscle: 

thisMuscle =

recfem_r

thisMuscle.getConcreteClassName()

ans =

Millard2012EquilibriumMuscle

thisMuscle = model.getMuscles.get('recfem_r');
thisMuscleSafe = Millard2012EquilibriumMuscle.safeDownCast(thisMuscle);
Unable to resolve the name Millard2012EquilibriumMuscle.safeDownCast.
I have tried using Opensim 4.0, 4.1 and their respective plugin versions which work in the GUI but safeDownCast does not there either. I have also tried Matlab 2020 and 2021 with either configured for 4.0 or 4.1, wondering if I need to be using an older version? Windows PATH has been changed, uninstalled and reinstalled all versions of everything.

Any help or suggestions would be much appreciated.

Re: Unable to safeDownCast to ConcreteClass

Posted: Wed May 19, 2021 12:52 pm
by aymanh
Hi Derek,

Actually what you see is the expected behavior. Plugins extend the set of available object types only in C++ so I wouldn't expect the ligament you loaded to be available in python or Matlab in any version. While you can't safedowncast to use the native object interfaces, you can still use the object as a part of a model (XML) or using the Object's generic interfaces to get/set/modify properties. Please let us know if you need help using this interface. You can also safedowncast to a Force or other classes on the hierarchy known to Matlab/Python if you want to use these.

Best regards,
-Ayman

Re: Unable to safeDownCast to ConcreteClass

Posted: Wed May 19, 2021 1:36 pm
by djacobs
Overall, I'm looking to access and change the slack length property of ligaments from trial to trial. While I understand not being able to access the ligament as it is part of a plug in, is this the same for the Millard muscles? I have seen examples in which they were accessed by safeDownCast to the concrete class and why I included a trouble shooting excerpt in which I was unable to downcast my recfem muscle which is a Millard2012 type muscle. Even after manual configuration (matlab & system path), my Matlab versions do not appear to be able to access the appropriate Opensim libraries.

thanks in advance for any insight if this has arisen before.

Re: Unable to safeDownCast to ConcreteClass

Posted: Thu May 20, 2021 4:44 am
by tkuchida
While I understand not being able to access the ligament as it is part of a plug in, is this the same for the Millard muscles? I have seen examples in which they were accessed by safeDownCast to the concrete class and why I included a trouble shooting excerpt in which I was unable to downcast my recfem muscle which is a Millard2012 type muscle. Even after manual configuration (matlab & system path), my Matlab versions do not appear to be able to access the appropriate Opensim libraries.
I am unable to find your script so it's difficult to determine the issue. Please see the examples on GitHub (search for "safedowncast" and filter the results for Matlab): https://github.com/opensim-org/opensim- ... fedowncast. Also, I suggest testing with a model that is shipped with OpenSim in case there is a model-specific issue.

Re: Unable to safeDownCast to ConcreteClass

Posted: Fri May 21, 2021 10:01 am
by aymanh
Hello,

I added documentation to show the use of PropertyHelper to help explain how to set/get values using the Properties interface here. The properties interface is the lowest level interface to get/set values in an Object but should be use only as a last resort since it's low level and side effects of editing may not be triggered properly.

https://simtk-confluence.stanford.edu/d ... ith+Matlab

Hope this helps,
-Ayman

Re: Unable to safeDownCast to ConcreteClass

Posted: Sat May 22, 2021 9:41 pm
by djacobs
Both of these posts, helped. Thank you!