Page 1 of 1

Translating python API code to matlab

Posted: Wed Apr 28, 2021 12:21 pm
by bhorsak
Hi,

I am just starting to use the opensim API for matlab. I have a line of code in python which I am trying to convert to matlab. However, I missing a specific part for the matlab code. I was trying now for hours to get a results and finally ended up with getting help here in the forum : ) Any hints more than appreciated:

Python version:
femContact = osimModel.getContactGeometrySet().get('femur_cartilage')
femContactMesh = osim.PropertyString_getAs(femContact.getPropertyByName('mesh_file')).getValue()

What I was not able to find in Matlab was the part 'PropertyString_getAs' - does anyone have an idea how this needs to be done in matlab?

Thank you, Brian

Re: Translating python API code to matlab

Posted: Mon May 03, 2021 11:27 am
by aymanh
Hello,

Not sure what version of openSim code/API you're using but what you need to do is something along the lines below in version 4.0+:

Code: Select all

femContact = osimModel.getContactGeometrySet().get('femur_cartilage') #will return a ContactGeometry
meshContact = osim.ContactMesh.safeDownCast(femContact) # make it into a proper ContactMesh that's aware of mesh files
femContactMeshFile = meshContact.get_filename(0) # get mesh file name from ContactMesh 
You should check the doxygen documentation (accessible through the GUI/Application and/or methodsview() in Matlab) of the version you're using to find out what methods/classes are available.

Best regards,
-Ayman