Page 1 of 1

Automatting Python Scripts - Error: "getCurrentModel()" is not defined

Posted: Tue Mar 12, 2019 4:29 am
by sigurdrifa
Hello community,

I'm working on some new modifications within the GUI. What I try to realize is an automatic script execution to add new bodies. For that I created a python script. If I execute it manually via GUI and Scripts > Run it works without problems.

Now I am trying to use a PythonInterpreter that executes it automatically when clicking on a button. I created a "helper" package similar to the Scripting Shell Subproject for that. First it executes ModelBuildingFunctions.py; second it should execute a CreateNewBody.py script that adds a sphere.

Unfortunately it does not work as I expected. I get this error:

Code: Select all

Traceback (most recent call last):
  File "../../../../CreateNewBody2.py", line 9, in <module>
    model = getCurrentModel().clone()
NameError: name 'getCurrentModel' is not defined
I am not very familiar with python, so I am a bit clueless why it does not work. Do you have any idea what sort of access is missing here?

Re: Automatting Python Scripts - Error: "getCurrentModel()" is not defined

Posted: Wed Apr 17, 2019 8:56 pm
by brycekillen05
Hi Jenny,

I can't say i'm fully familiar with your problem but I have worked with the Python API in OpenSim 3.3 . Just to clarify, are you trying to run the script as a standalone .py script through Anaconda or through the OpenSim GUI ?

From what I can see, you are trying to run the function, getCurrentModel() , looking at the OpenSim 4.0 doxygen page https://simtk.org/api_docs/opensim/api_docs/, I can't actually see that function. I'm not sure if there is a different set of functions available when running through the GUI vs standalone python scripts.

If you are able to clarify where you are running your script this might start to get to the bottom of the problem.

Cheers

Re: Automatting Python Scripts - Error: "getCurrentModel()" is not defined

Posted: Thu Apr 18, 2019 6:54 am
by jimmy
The GUI shell is Jython interpreter and has a lot of calls that are only native to GUI shell-- getCurrentModel() can only be called in the GUI.