Printing IK setup file through Matlab doesn't populate model file field in resulting .xml

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Mark Price
Posts: 5
Joined: Tue May 31, 2016 11:02 am

Printing IK setup file through Matlab doesn't populate model file field in resulting .xml

Post by Mark Price » Tue Jul 11, 2017 9:54 am

When using the IK tool through the Matlab API, I noticed that if I use setModel and then print to an .xml, the "model file" field in the .xml remains unchanged. Setting other parameters then printing does update those fields in the .xml. Is this a bug or am I doing something wrong?

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Printing IK setup file through Matlab doesn't populate model file field in resulting .xml

Post by jimmy d » Tue Jul 11, 2017 10:55 am

InverseKinematicsTool().setModel() takes a Model object as input, not a path to a model. Models can be VERY big, so it would be difficult to print everything in the model to the setup file. Whereas the ikTasks (the number of markers or coordinates you want to track) are relatively small in number.

It may be nice to have a constructor that takes a path to a model file, rather than a Model object, but that isn't possible at the moment.

If you need to keep a track a model being used in the .xml, you could use an xml editing program/function to write in the path to the model.

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Printing IK setup file through Matlab doesn't populate model file field in resulting .xml

Post by jimmy d » Tue Jul 11, 2017 11:08 am

Actually, I just remembered that there is a hack that you can use to change a property. This is a 'use at your own risk' method, since messing with properties can be dangerous. DO NOT change the property and then try to run the tool. Once you have run the tool, edit the property and print.

Code: Select all

% Instantiate an IK tool      
ik = InverseKinematicsTool();
        
% Get a reference to an abstract property of the object. It is equivalent 
% to having the XML tag name <factor> in an .osim file.
% ie AbstractProp  = Object.getPropertyByName(<factor>)
factorProp  = ik.getPropertyByName('model_file');
% get its value (it should be empty since we created a blank iktool)
path2model = PropertyHelper.getValueString(factorProp);
% Set the value for this string to the model path
PropertyHelper.setValueString('path2model',factorProp);
% print the setup file
ik.print('setup.xml')



User avatar
Mark Price
Posts: 5
Joined: Tue May 31, 2016 11:02 am

Re: Printing IK setup file through Matlab doesn't populate model file field in resulting .xml

Post by Mark Price » Tue Jul 11, 2017 2:56 pm

Interesting, thanks a lot for the replies. I was mostly trying to do this to edit the property without necessarily running the IK tool itself, just exporting a setup file for later use - automatically assigning different models to different IK tasks based on a couple variables. I think it should be relatively safe given that.

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Printing IK setup file through Matlab doesn't populate model file field in resulting .xml

Post by jimmy d » Tue Jul 11, 2017 3:41 pm

Yeah, the operations you suggest sound fine. It is when you have a live Model loaded, mess with properties under the hood, and try to run it— that will most likely lead to disaster. Goodluck!

POST REPLY