Create simple model from scratch
- Raul Munoz
- Posts: 7
- Joined: Wed Nov 11, 2020 7:31 am
Create simple model from scratch
Dear All,
I'm a new user of OpenSim. I would like to learn how to create a very simple model from scratch, so I am trying to run an example (build_simple_arm_model.py) from either Script/Run menu or the ScriptingShell Window, but the following error message is displayed in the ScriptingShellWindow: No module named opensim.
I have tried to run the same script from Spyder (run build_simple_arm_model.py) and no error is shown, but I can't see any animation. Basically, a new window pops-up where I just can see the floor and a 2D arm.
I'm using Windows7, Anaconda3 (python 3.7) and OpenSIM 4.1.
I would greatly appreciate your help.
Thank you in advance,
Raul
I'm a new user of OpenSim. I would like to learn how to create a very simple model from scratch, so I am trying to run an example (build_simple_arm_model.py) from either Script/Run menu or the ScriptingShell Window, but the following error message is displayed in the ScriptingShellWindow: No module named opensim.
I have tried to run the same script from Spyder (run build_simple_arm_model.py) and no error is shown, but I can't see any animation. Basically, a new window pops-up where I just can see the floor and a 2D arm.
I'm using Windows7, Anaconda3 (python 3.7) and OpenSIM 4.1.
I would greatly appreciate your help.
Thank you in advance,
Raul
Tags:
Re: Create simple model from scratch
I'm not sure if you installed the opensim python package. I don't have anaconda just plain python 3.7.9 on Windows 10. If you haven't installed the opensim python package, you would do it by cd'ing to the opensim folder. In my system it looks like this:
cd C:\OpenSim 4.1\sdk\Python
and then run something like this
python setup.py install
(from: https://simtk-confluence.stanford.edu/d ... +in+Python)
cd C:\OpenSim 4.1\sdk\Python
and then run something like this
python setup.py install
(from: https://simtk-confluence.stanford.edu/d ... +in+Python)
Last edited by Ricardo P on Sat Dec 12, 2020 2:59 pm, edited 1 time in total.
- Raul Munoz
- Posts: 7
- Joined: Wed Nov 11, 2020 7:31 am
Re: Create simple model from scratch
Thank you for your help, Ricardo. I think the opensim python package is installed. At least, I followed the steps indicated in the website you have suggested (including python setup.py install).
The folder C:\OpenSim 4.1\sdk\Python is available in my computer and when I type "import opensim" in Spyder, no errors are shown. However, if I type the same command in the ScriptingShell window, it does not recognise it.
Please, more suggestions are welcome.
The folder C:\OpenSim 4.1\sdk\Python is available in my computer and when I type "import opensim" in Spyder, no errors are shown. However, if I type the same command in the ScriptingShell window, it does not recognise it.
Please, more suggestions are welcome.
Re: Create simple model from scratch
Hi Raul. I hear you. I installed this package recently and had a similar question. The scripting shell is not a full fledged python interpreter. It's not Python but rather "Jython". You can't do the same things that you can do in an IDE (I haven't used Spyder and I use VS code instead. I'm guessing that for the purposes of this discussion both Spyder and VS Code are the same since they both call Python 3.7 libraries and not Jython). As far as I can tell, if you want to use the "Scripting Shell" you should have an easier time running some of the scripts in folder C:\Users\username\Documents\OpenSim\4.1\Code\GUI but you would probably have a harder time running the scripts in C:\Users\username\Documents\OpenSim\4.1\Code\Python.
I wish the help documents made that comment but I don't recall seeing anything like that when I read them.
I wish the help documents made that comment but I don't recall seeing anything like that when I read them.
- Raul Munoz
- Posts: 7
- Joined: Wed Nov 11, 2020 7:31 am
Re: Create simple model from scratch
Thank you again, Ricardo. I have tried to run the example scripts from the main menu (Script/Run) and they don't work either. There must be something wrong in the installation, but I can't see what.
- Thomas Uchida
- Posts: 1797
- Joined: Wed May 16, 2012 11:40 am
Re: Create simple model from scratch
Suggestions on how to improve the documentation are always welcome. For an introduction to scripting, please see the "Scripting" page (https://simtk-confluence.stanford.edu/d ... /Scripting). There are some small differences between the scripting shell and Python; many of these are described on the "Common Scripting Commands" page (https://simtk-confluence.stanford.edu/d ... g+Commands).I wish the help documents made that comment but I don't recall seeing anything like that when I read them.
- Raul Munoz
- Posts: 7
- Joined: Wed Nov 11, 2020 7:31 am
Re: Create simple model from scratch
Thank you for your help, Thomas.
Coming back to my problem (I can't run the examples from the script/run menu), is there anything I can do to check that Python is properly installed and linked to OpenSIM? If Spyder works fine and my OpenSIM can load models with *.osim extension, but I can't run python scripts from OpenSIM, the problem seems to be between OpenSIM and Python, right?
Please, any further help would be appreciated.
Coming back to my problem (I can't run the examples from the script/run menu), is there anything I can do to check that Python is properly installed and linked to OpenSIM? If Spyder works fine and my OpenSIM can load models with *.osim extension, but I can't run python scripts from OpenSIM, the problem seems to be between OpenSIM and Python, right?
Please, any further help would be appreciated.
- Thomas Uchida
- Posts: 1797
- Joined: Wed May 16, 2012 11:40 am
Re: Create simple model from scratch
A script that runs in Spyder (Python) will generally not run in the GUI (Jython). You can find more information on the documentation pages I linked above. For some examples, you can compare the scripts in your Resources/Code/GUI directory with the scripts in your Resources/Code/Python directory.If Spyder works fine and my OpenSIM can load models with *.osim extension, but I can't run python scripts from OpenSIM, the problem seems to be between OpenSIM and Python, right?
- Raul Munoz
- Posts: 7
- Joined: Wed Nov 11, 2020 7:31 am
Re: Create simple model from scratch
Thank you, Thomas. Now I understand.
I have noticed that some examples included in the Resources/Code/GUI directory work, but others such as createRodForPendulum.py show some errors:
Jython Interactive Console
>>> Traceback (most recent call last):
File "C:\Users\mycomputername\Documents\OpenSim\4.1\Code\GUI\createRodForPendulum.py", line 13, in <module>
rod = addBodyToModel(model, 'rod')
NameError: name 'addBodyToModel' is not defined
How or where should I run this script to make it work?
Many thanks.
I have noticed that some examples included in the Resources/Code/GUI directory work, but others such as createRodForPendulum.py show some errors:
Jython Interactive Console
>>> Traceback (most recent call last):
File "C:\Users\mycomputername\Documents\OpenSim\4.1\Code\GUI\createRodForPendulum.py", line 13, in <module>
rod = addBodyToModel(model, 'rod')
NameError: name 'addBodyToModel' is not defined
How or where should I run this script to make it work?
Many thanks.
- Thomas Uchida
- Posts: 1797
- Joined: Wed May 16, 2012 11:40 am
Re: Create simple model from scratch
Sorry, but I don't know what the addBodyToModel() method is. It is not part of the OpenSim API (https://simtk.org/api_docs/opensim/api_docs/). The author probably intended to use addBody() (https://simtk.org/api_docs/opensim/api_ ... db5aca5777), however the script still won't work as written (you would need to create the Body, add it to the Model, create a Joint between Ground and the new Body, and add the Joint to the Model). Perhaps take a look at the example in the README.md file on GitHub: https://github.com/opensim-org/opensim-core.