Running python script in Blender
Question:
I installed Blender 2.6 and I’m trying to run a script called drawcar.py (Which uses PyOpenGL)
I looked around the documentation for importing a script and could only access Blender’s python console.
How do I run drawcar.py from the Linux terminal with Blender?
Answers:
- Open a Text Editor view in Blender.
- Press Alt + O, or go to Text>Open Text Block and open the .py file
- Then simply press Run script 😀
P.s. Instead of opening a file in step 2, you can also hit the "+ New" button and create a new script instead.
Note : In newer versions the Run Script button label has been replaced with a Play icon :
You can also execute the following code in the python console to execute an external script without opening it up in the text editor:
filename = "/full/path/to/myscript.py"
exec(compile(open(filename).read(), filename, 'exec'))
The above code comes from the following link:
It is likely that drawcar.py is trying to perform pyOpenGL commands inside Blender, and that won’t work without modification. I suspect you are getting some import errors too (if you look at the command console). Blender has it’s own internal python wrapper for opengl called bgl
, which does include a lot of the opengl standards, but all prefixed by bgl.
If you have a link to drawcar.py I can have a look at it and tell you what’s going on.
To run a script by another script or from console:
import bpy
script = bpy.data.texts["script_name.py"]
exec(script.as_string())
this answer is too late, but to help anyone with the same problem
via the terminal:
blender yourblendfilenameorpath --python drawcar.py
from the man pages
-P or --python <filename>
Run the given Python script file.
I installed Blender 2.6 and I’m trying to run a script called drawcar.py (Which uses PyOpenGL)
I looked around the documentation for importing a script and could only access Blender’s python console.
How do I run drawcar.py from the Linux terminal with Blender?
- Open a Text Editor view in Blender.
- Press Alt + O, or go to Text>Open Text Block and open the .py file
- Then simply press Run script 😀
P.s. Instead of opening a file in step 2, you can also hit the "+ New" button and create a new script instead.
Note : In newer versions the Run Script button label has been replaced with a Play icon :
You can also execute the following code in the python console to execute an external script without opening it up in the text editor:
filename = "/full/path/to/myscript.py"
exec(compile(open(filename).read(), filename, 'exec'))
The above code comes from the following link:
It is likely that drawcar.py is trying to perform pyOpenGL commands inside Blender, and that won’t work without modification. I suspect you are getting some import errors too (if you look at the command console). Blender has it’s own internal python wrapper for opengl called bgl
, which does include a lot of the opengl standards, but all prefixed by bgl.
If you have a link to drawcar.py I can have a look at it and tell you what’s going on.
To run a script by another script or from console:
import bpy
script = bpy.data.texts["script_name.py"]
exec(script.as_string())
this answer is too late, but to help anyone with the same problem
via the terminal:
blender yourblendfilenameorpath --python drawcar.py
from the man pages
-P or --python <filename>
Run the given Python script file.