Page 1 of 1

Problem adding an Analysis to a Model using API from Python

Posted: Thu Feb 08, 2018 3:01 pm
by manunez
Hi! I'm using the 3.3 API with python. This example:

Code: Select all

import opensim
m = opensim.Model()
a = opensim.MuscleAnalysis()
m.addAnalysis(a)
throws:

Code: Select all

/usr/local/lib/python2.7/dist-packages/opensim-3.3-py2.7.egg/opensim/opensim.pyc in addAnalysis(self, analysis)
  69848         val = _opensim.Model_addAnalysis(self, analysis)
  69849 
> 69850         args[0]._markAdopted()
  69851 
  69852 

NameError: global name 'args' is not defined
Any idea as to why? Is there a workaround for this? The idea is to append a bunch of Analyses to a Model and then feed it to an AnalyzeTool.

Re: Problem adding an Analysis to a Model using API from Python

Posted: Thu Feb 08, 2018 3:34 pm
by chrisdembia
This results from using a version of SWIG that is too recent. Try using SWIG 3.0.2. Or, you have to edit the opensim.py file that SWIG generates: replace "args[0]" with "analysis".

This issue is fixed in the 4.0 code base.

Re: Problem adding an Analysis to a Model using API from Python

Posted: Thu Feb 08, 2018 4:00 pm
by manunez
Yep, that's it. I just tried it on a Windows machine with a release install of OpenSIM and works fine. I guess the switch to 4.0 is becoming more and more of a necessity. I'll give it a thought once the compiling instructions for the GUI in Linux are available :lol:

By the way, that was opensim.pyc, and in the opensim.py from the same folder I could not find a single mention to "args[0]". Strange...

Thank you very, very much!

Re: Problem adding an Analysis to a Model using API from Python

Posted: Thu Feb 08, 2018 4:11 pm
by chrisdembia
I'll give it a thought once the compiling instructions for the GUI in Linux are available :lol:
The best you'll get is the Travis CI script: https://github.com/opensim-org/opensim- ... travis.yml

And yes, that is strange. The file is very large, though; are you sure it fully loaded before you searched?

Re: Problem adding an Analysis to a Model using API from Python

Posted: Sat Feb 10, 2018 4:47 pm
by manunez
Even worse: had my editor's search set for regex searches :roll: