Page 1 of 1

Scale a Model with a Script

Posted: Thu Sep 19, 2013 2:33 am
by uschulz
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

Re: Scale a Model with a Script

Posted: Sun Sep 22, 2013 12:34 am
by saxbyd
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

Re: Scale a Model with a Script

Posted: Mon Feb 29, 2016 7:51 am
by godfreap
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!

Re: Scale a Model with a Script

Posted: Tue Mar 01, 2016 10:56 am
by jimmy
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.