Problem adding an Analysis to a Model using API from Python

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Marcos Alfredo Núñez
Posts: 22
Joined: Thu Sep 01, 2016 1:41 pm

Problem adding an Analysis to a Model using API from Python

Post by Marcos Alfredo Núñez » Thu Feb 08, 2018 3:01 pm

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.

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

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

Post by Christopher Dembia » Thu Feb 08, 2018 3:34 pm

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.

User avatar
Marcos Alfredo Núñez
Posts: 22
Joined: Thu Sep 01, 2016 1:41 pm

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

Post by Marcos Alfredo Núñez » Thu Feb 08, 2018 4:00 pm

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!

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

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

Post by Christopher Dembia » Thu Feb 08, 2018 4:11 pm

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?

User avatar
Marcos Alfredo Núñez
Posts: 22
Joined: Thu Sep 01, 2016 1:41 pm

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

Post by Marcos Alfredo Núñez » Sat Feb 10, 2018 4:47 pm

Even worse: had my editor's search set for regex searches :roll:

POST REPLY