Scale a Model with a Script

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Ursula Schulz
Posts: 4
Joined: Fri Mar 22, 2013 4:12 am

Scale a Model with a Script

Post by Ursula Schulz » Thu Sep 19, 2013 2:33 am

HI!

I'm rather new in this topic and i have a beginners question.

I have to scale a Model without using the GUI of OpenSIm. I want to do to it with a script in MATLAB. With the Gaittoolbox I generate a StaticScale_Setup.xml file with data from a c3d.file.

I found a opperuntiy to do it with the command line. but i get a errorw masssage

"failure reading object from file [MeasurementSetFile] cwd =C:\OpenSim 3.0\VERSUC
HE\V15_Parse_c3dError:SimTK Exception thrown at Xml.cpp:70:
Error detected by Simbody method Xml::readFromFile(): Failed to load the Xml f
ile 'MeasurementSetFile' with error 'Failed to open file (line=0, col=0)'.
(Required condition 'loadOK' was not met.)"


but if I use the Scale_Setup file in OpenSim with the ScalingTool it works!

i would be very gradful if someone can help me. maybe to fix the errow massage or with another way to solve my problem.

best regards

Ursula

User avatar
David John Saxby
Posts: 83
Joined: Mon May 09, 2011 8:39 pm

Re: Scale a Model with a Script

Post by David John Saxby » Sun Sep 22, 2013 12:34 am

Hey Ursula,

I would be careful using Matlab to parse, edit, compile xml's for execution in OpenSim.

I don't know the exact reason for this, but OpenSim does not provide a grammar for the xml's it uses, so you are guessing a bit when you edit/create them. This leads to problems with command line execution.

The most robust approach is to create a blank scale xml through the GUI. Then use the Matlab API wrappers to call the scale function directly.

The pseudo code:

1) import matlab exposed opensim classes

2) Use the ScaleTool constructor on the blank xml

3) Use the Model constructor on the model file

4) instantiate

5) Get the trc date for the operation using MarkerData constructor

6) Set the operator parameters: name, start and end frame, mass, height, time array, output options

7) Print the tool for posterity

8) Execute the tool

I think future releases/documentation will have examples of more API operations.

Best,

David

User avatar
Aaron Godfrey
Posts: 55
Joined: Tue Feb 16, 2016 12:34 pm

Re: Scale a Model with a Script

Post by Aaron Godfrey » Mon Feb 29, 2016 7:51 am

Very old post I know, but should you still exist, can you elaborate on how to adjust the blank XML with Matlab? Right now, my idea is to fill in the XML's variables with specific strings I can then search & replace using strrep in Matlab.

Thanks!
Last edited by Aaron Godfrey on Fri Mar 04, 2016 6:08 am, edited 1 time in total.

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

Re: Scale a Model with a Script

Post by jimmy d » Tue Mar 01, 2016 10:56 am

XML reading and writing is out of the scope of OpenSim documentation. Rather use the API to Instantiate a ScaleTool and edit programmatically and write the example to file (xml).

Scripting documentation is here.
Scaletool documentation is here.

There is also GUI script examples of scaling in your OpenSim/Scripts/GUI_Scripting that can be easily augmented for Matlab.

POST REPLY