Tuesday, February 16, 2010

Python/Blender Tutorial

I decided I would learn python since I can actually do things with it and learn/practice programming concepts at the same time. I might as well keep this blog running with it so here's the first of (hopefully) a series of Python/Blender tutorials. Also, I will try to keep these in the Blender 2.5+ stage, so it's quite a bit different in both Blender aspects and differences between Python 2.6 and 3.1. You should be able to do this in Blender 2.5 alpha 0, but if you have any issues, try getting the latest build from GraphicAll, or building the latest SVN yourself.
----------------------------------------------------------------------------------
Tutorial 1. Saying Hello.
----------------------------------------------------------------------------------
First of all, Download Blender.
Method 1:
You can get it at http://www.blender.org/ I'll be using current SVN builds, so you'll want to get blender 2.5 alpha 0. You should be able to find it, but here's a link anyways. http://www.blender.org/download/get-25-alpha/
It should be fairly stable, but have less features than newer builds. Alpha 1 will come out very soon, and will be a lot better.
Method 2:
You can also get a newer build at http://www.graphicall.org/ There should be one that works, and it's fairly stable now, although be aware that random crashes and bugs do happen.
Method 3:
Build your own! I made a post about this earlier, so scroll down and follow it. It'll take a lot longer, but it's good experience to build something yourself. It will likely be a bit more stable than other builds, but for simple python scripting, you probably won't notice.
Get it whatever way you like. I would recommend getting a build from GraphicAll if you're just doing this, and don't want to build your own.
Start it up and make sure it works. If not, install the Visual C++ redistributable package.
The next step would be to get Python. Blender 2.5+ uses 3.1, so I would recommend it. You might not need it, but it's a good idea to get it if you're serious about learning Python. Blender does have bundled Python, but it doesn't do as much.
+++++++++++++++
On with the tutorial!
+++++++++++++++
If you've never used blender before, you should probably learn it a bit before you do this so you can know what you are messing with. Here's a good set of tutorials to get you started with this amazing free sofrware. If it's only about 2.4x, don;t worry. the basics are the same with 2.5x, just better. http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro
If you are still reading, I assume you understand the basics of blender. Open the default scene, and move your mouse to the top-right of the 3D view. click and drag to the left. You just split the view the 2.5 way. split the new one vertically, and switch the top new view to console, and the bottom to text editor. in the text editor view, click the little notebook icon, and then text. This is a new text document that is in the default scene already. To the right of that icon, it there are 3 little buttons to click. The first one is for line numbers, the second, word wrap, and the third, syntax highlighting. Now type the following:

import bpy
print ("Hello.")

Now press alt+p, or click Run Script.
It didn't look like it did anything, but it really did. look at blender's other window and see.
It just said Hello.

No comments: