Page 1 of 1

Set ForceSet to AnalyzeTool-Instance with Python API

Posted: Tue May 31, 2016 4:46 am
by stefaniegassel
Hey there,

I like to run Static Optimization from within Python using the Python Wrapper. Thus I create an analyzeTool from a template setupXML file and then fill in the specific values e.g. for the coordinate file to use.
> analyzeTool = opensim.AnalyzeTool(setupXMLFile)
...
> analyzeTool.run()
The tool basically runs through. However I need to set the force set file to add actuators, which is failing unfortunately... I already tried the following ideas:


1. I tried to set it programmatically:

forceSetFile = "I:/somePath/Actuators.xml"
arr = opensim.ArrayStr()
arr.append(forceSetFile)
analyzeTool.setForceSetFiles(arr)
--> It runs through without errors, but seems to ignore the file and doesn't give the usual output "Adding force object set from "I:/somePath..."

2. I tried to already add the file in the setupXMLFile
<force_set_files>I:/somePath/Actuators.xml</force_set_files>
--> Now the analyzeTool doesn't seem to parse the setup XML file and the scripts exits with an undefined error

Do you know a way to set the force set file? Maybe using the class ForceSet and creating an instance of it?



And one more Question: I know that the above mentioned problem works when I save a final setup file and run it via console using > os.system("analyze -S \"finalSOSetupFile.xml\"") instead of using > analyzeTool.run(). But how can I save out the currenct analyzeTool-Settings to a setup script with the Python API?

The function > analyzeTool.print(setupFilePath) - which used to work as Python script from within OSIM - doesn't work in the Python Wrapper --> invalid syntax "print". And analyzeTool.printResults also doesn't show any effect. Could you please tell me which command to use instead?

Any help is appreciated! Thank you very much!
Stefanie

Re: Set ForceSet to AnalyzeTool-Instance with Python API

Posted: Tue May 31, 2016 8:57 am
by bradh
There is a post on the forum (could not quickly find it) that says not all of the Static Opt methods were made available as of 3.3 (but are supposed to be in the next coming release). The work around I came up with was to make a simple Static Opt xml template file (basically one with minimal options in it) and then load it in and modify it. Very similar to what you are doing. Mine was:

Code: Select all

modelRef=modleing.Model("YourModelHere.osim")
tool=modeling.AnalyzeTool("StaticOptimizationTemplate.xml")
tool.setModel(modelRef)
Then you should be able to use the tool.setForceSetFiles() method.