# Using python scripts

Wednesday, March 17th, 2010

# This page is here to help you understand how to use basic python scripts in blender 2.4x.

It’s not about writing scripts, just using them.

I assume you know enough about blender to open windows, find menus, and open files in it.

I will only cover Windows on this page. I don’t have the other Operating systems handy. Also using scripts in the Game engine can be a bit different than how I explain here.

# What is python?

If you really want to know everything about python you should go to python.org but I’ll give a simple description here.

Python is a programming language released originally by yet another Dutchman. I know they’re everywhere! You can read more about it’s history on this page if you want.

The thing that makes python unlike C or C++ for instance is that you don’t have to actually compile your programs. Basicly all programming languages are written in basic text. Programs written in C you would ‘compile’, which would turn your code into a program that you can use and give to people. So for example with python you don’t generate a blender.exe file.

In stead the programming code stays in it’s basic text format, in what is really just a textfile, nothing more. This textfile can be read by a ‘real’ program which is called python as well (just like the language). This program then does all the things that it’s told to do in the textfile.

These textfiles are called python scripts. And scripts are files that tell programs what to do, they are not programs themselves. There are lots of other languages that work in the same way… like asp, php, and javascript.

# The infamous blender startup message!

You may have seen this screen before and it scares a lot of people at first. I mean… it’s an actual bonafide error message…. or is it?

Do not close this screen!

This screen is used by blender to show you messages, if you close it you will close blender as well.

Let me try to explain where the message comes from.

We can use python scripts in blender. Now we can only do so because inside blender is a small version of the python program that can read these scripts, and do what they say. That’s where the first line comes from. Apparently the copy of blender that I took this screenshot from had python 2.5 put in it. The actual line of text is created by the python program in blender when it’s started. Now as the python program in blender is started (when you start blender) it has a look at itself and your computer to see what it can do, where it is, and basicly everything I do every morning when I wake up.

So it wakes up and finds out it’s the small version. Then it has a look to see if there’s a big version of itself on your computer that would allow it to do everything the big version can do. In this case it can’t find it, and all the other messages you see basicly mean: ‘Hey I am only the small version inside blender, and I can’t do everything I could do if my big brother was here’. This is no reason for anyone to worry! Really it isn’t. The small version inside blender can do pretty much everything you want. Only for the really advanced stuff like communicating with big databases and such, would you need the complete version of python.

So we have blender, and we can use pretty much all python scripts released for blender in it. You can install a full version of python if you really need it, or if you want to get rid of those messages, but normally there really is no need. I use python all the time and don’t need a full version at all.

# I downloaded a script… now what?

Ok so you have a script. Lets call it myScript.py, and remember that really all it is is a textfile. You can use the script inside blender in two basic ways.

# One: Put the file in the blender scripts folder

If you put the script you downloaded in the same folder as all the scripts you get with blender you can use it as if its one of those official scripts. If you are on windows find the folder that has the blender.exe program file in it and there should be a folder called ‘.blender’. In that folder should be another folder called ‘scripts’. This is where all the official scripts are.

Once you put the file in there you can find it in the blender scripts menu. Don’t forget to use the ‘Update menus’ function at the top of the menu if you had blender already running when you put the script in the folder. As soon as you select the script in this menu it will ‘run/be executed’

If you are not sure where to find the script in this menu you can open it in a text editor (notepad for instance) and near the top it should say what group it’s in. That is where you’ll find it in the menu. If you can’t find the group, you’ll have to use the second way.

# Two: Open the script as a textfile.

Save the script anywhere on your computer. Then in blender open a text window, and in there open the file like a textfile.

Now if you have your mouse pointer over the text window and you click ALT + P the script will run.

# Having the right blender version.

Every script should tell you for what blender version it was written at the top of the script itself. There is no guarantee that a script will work if you have a newer or older version of blender than the one for which the script was written.

# That’s it.

You should now know enough to use most python scripts in blender.

Have fun!
Dolf