Page 1 of 1

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

Posted: Tue Jul 11, 2017 9:54 am
by mprice
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?

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

Posted: Tue Jul 11, 2017 10:55 am
by jimmy
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.

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

Posted: Tue Jul 11, 2017 11:08 am
by jimmy
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')



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

Posted: Tue Jul 11, 2017 2:56 pm
by mprice
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.

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

Posted: Tue Jul 11, 2017 3:41 pm
by jimmy
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!