This blog contains the scripts for my Blender 3D YouTube videos. They're published as follows:
Buy The Blender 3D Cookbook as a book!
Buy the Blender 3D Cookbook for your iPad!
Buy the Blender 3D Cookbook for your Kindle!
Showing posts with label scripts. Show all posts
Showing posts with label scripts. Show all posts
Thursday, July 15, 2010
Blender 3D Cookbook, Volume 1
I am pleased to announce the publication of Volume 1 of my Blender 3D Cookbook available from lulu.com, either as a book or a PDF download, at:
http://www.lulu.com/product/paperback/the-blender-3d-cookbook-volume-1/11777448
The Blender 3D Cookbook consists of the scripts to 62 or my my Blender 3D tutorials, at http://www.youtube.com/irakrakow. Each script has a link to the Youtube video, if you purchase the book as a PDF. If you purchase the book, the URL is printed. Many of you have requested such a book. I called the book a “cookbook” because you can think of the scripts as “recipes” for producing a desired effect in Blender.
I don't assume any particular level of Blender expertise. My videos cover a wide variety of topics, from beginner to advanced, including some that I have not seen as tutorials anywhere else. Like a cookbook, you can pick and choose those recipes you are interested in and skip the ones that you either know about or that you're not interested in. I tried to include something for everyone, including topics such as the Blender Game Engine and Python scripting that have only been lightly covered in other tutorials. If you have suggestions for future tutorials, please email me at ira.krakow@gmail.com.
As of this date, Blender is undergoing a massive rewrite and restructuring. The current, production version, 2.49b, will eventually be replaced by version 2.5. 2.5 has a different user interface and has many improvements to old features, as well as many new features. It is currently in alpha, which means that there could be some changes made until the day when 2.5 becomes the production version of Blender. On my Blender 3D forum, at http://forum.irakrakow.com, I took a survey of who used what version. I discovered that roughly half worked in Blender 2.4x (although 2.49b is the most current production version, some were working in earlier versions), and the other half worked in Blender 2.5. I have written tutorials based on both versions. For each tutorial, I note which version (2.49 or 2.5) I made it for. Some of the 2.5 tutorials were done in different alpha versions, such as Alpha 0 or even pre Alpha. For the most part, the effects I write about can be produced in any version.
These tutorials are not intended to cover every conceivable Blender feature. That would, in my opinion, be too thick a volume. Note that I suffixed the title to this cookbook “Volume 1”. Blender is too complex and rich a program, undergoing constant upgrading and changing, for that. I plan on publishing many more volumes of the Blender 3D Cookbook, in the future, that will explore other amazing and unique Blender features.
I welcome your feedback and hope you enjoy my cookbook.
Wednesday, March 10, 2010
Python 3, Part 5 (List Methods)
In Part 4, we saw how to use slicing to work with parts of a string, list, or tuple, as well as how to insert, delete, and add to these types of variables. Python has a number of built in methods -- also called functions -- that can do these operations in a way that makes the code easier to read. Sometimes it's a bit hard to understand all those colons and square brackets, and it's easier to use words like append, remove, or insert, which are, indeed the names of methods associated with lists. We'll also see how these easy to understand methods can be used to build a simple stack (where the last element added is the first element retrieved) or queue (where the first element added is the first element retrieved). We'll also discover how to sort, count, and locate items in a list. Along the way, we'll learn about the autocomplete feature of Blender's Python console, a handy feature that documents available methods.
Python 3, Part 4 (Slicing)
In Part 3, we were introduced to lists, which lets us work with more than one variable at once. We also saw how to reference parts of the list, say the 3rd element in the list x as x[2] (since we start numbering from 0), using the [] operator, and how to use negative numbers to reference list elements from the end. In this tutorial, we will go into more detail about how to get parts of strings and lists, by use of slicing. Slicing also uses the square brackets, but in a new and different way.
Labels:
blender 2.5,
programming,
python 3,
scripts,
slicing,
tutorial
Monday, March 8, 2010
Python 3, Part 3 (Lists)
In Part 2, we saw different ways that string variables can be defined. In this tutorial, we will see how lists of variables can be defined and used. You're basically creating more than one variable at a time, in a structure called a list. Lists are a very important part of Python. If you want to be able both program in Python and to read Python code written by others, you need to know how lists work. Don't worry, you'll get the hang of it if you practice a bit.
Monday, November 2, 2009
Blender Python 1: Setup
In addition to everything else, Blender is a programming environment, with Python its language of choice. Even if you don't plan on creating Python scripts in Blender, you should understand the Python environment. Python is how Blender talks to you. The purpose of this tutorial is to introduce you to Blender's Python environment. Understanding this environment should help you understand how Blender works as well. Of course, if you want to write Python scripts to make Blender behave exactly how you want, becoming familiar with the Blender Python environment is the first step. Even if you don't program, just understanding how to run a script will allow you to run Python programs, called scripts, written by others. For starters, go to the Blender Python Scripts Catalog.
Did you ever wonder what the purpose of the first window, and what the message:
Compiled with Python 2.6.2
Checking for installed Python... got it!
means? Does it have anything to do with big, poisonous snakes?
No. That first window is Blender's Python console. That message, which is what you should see as well, means that Blender found a good Python installation on your computer and that it could run Python programs. Blender also reports the Python version it found. You should, in general, go with the latest, most stable release of Python, which you can find at:
http://www.python.org
Python programs, incidentally, are called scripts and have the same meaning scripts have in the theatre. They're instructions for Blender. Blender uses Python scripts everywhere - to create objects, to move objects around in a scene, to animate objects, to add materials and textures, and so on.
Blender has two windows that were designed for interacting with Python. The Scripts window, the one with the snake icon, was designed to run Python scripts. The scripts are grouped into areas such as Mesh, Object, and UV. To run a script, select it from the menu. One commonly used script is to save the UV Face Layout to a file, for use with an image editor such as The Gimp or Photoshop. When you run the script, a screen with options for the UV image file displays. You can accept the defaults, or change them, and then press OK. The script will then run, asking you where you want to create the face layout file.
Blender has a built in Scripting setup, which works well if you want to create Python scripts in Blender. To access this window, go to the SR:5-Scripting view, which you can select from the dropdown menu. There are three windows: the 3D viewport, on the left; the Buttons Window, with the Scripts area highlighted, at the bottom; and the Text window at the right.
You have probably downloaded blend files with notes in the Text window. That's a great use for the text window. Another is to write Python scripts for Blender. Let's write our first Python script, a message to the Blender console announcing our presence. Type:
print "Ira was here."
in the Text window.
To run a script, you can either press Alt-P, or from the Text Menu, select Run Python Script. Press Alt-P. Seemingly, nothing happened. Blender is strangely silent if things go OK. Actually, the script run. To see the result, go to the Blender console, and the message "Ira was here." displays.
Blender will, however, tell you when you have made a programming error. Let's introduce an error. Text needs to be enclosed on each side by double quotes. Delete the last double quote. Press Alt-P. You get the following message:
Error: Python Script Error
Check console
Now that you have gotten this far, you know where to look. Click on the console window. You get the message:
SyntaxError: EOL while scanning string literal
File "Text" Line 1
and it shows you where it thought the error was. Actually, the error isn't quite where the message is pointing, but you have to give Blender a gold star for trying to be helpful.
Go back to the text window, add the double quote back, press alt-P, and check the console window. Everything is OK again.
Here are some formatting tips. Press the computer window icon. This makes the text window full screen. If your script is large, it's easier to have the window full screen so you won't have to scroll up and down as much. To return to the text window's original size, press the computer window icon (the screen is divided into 4 parts).
The next button displays line numbers along with the code. This can be very handy, especially considering that Blender's error messages give you the line number. Line numbers make it easier for you to get to a particular line.
The next window enables word wrap. Generally you don't want that button enabled when you are writing a script, although it is handy if you are writing notes or free form text in the window.
The "AB" button enables syntax highlighting. This is useful in coding to give you hints as to the proper syntax of a line of code.
The snake button enables Python text plugins. Text plugins can give the Text editor more power. You can find text plugins by going to the Text menu and selecting Text Plugins.
The Screen dropdown lets you change the font size. The code currently displays with a font size of 12. You can change it to 15 by selecting 15. Your choices depend on the fonts installed on your computer.
The Tab: selector lets you change the number of spaces that the editor inserts when you press the Tab key. Python syntax checks based on having the code properly tabbed. Making the indent larger helps the readability of the code as well. You can add a tab by placing the cursor at the beginning of the line and selecting Indent from the Format menu. You can also unindent.
Highlight the line "Ira was here". You can comment it out by selecting Comment from the Format menu. Commenting a line of code means that the code will not execute, i.e., run. To show this, press Alt-P to run the program. The message does not display on the console. You can uncomment by selecting Uncomment from the Format menu. Press Alt-P to run the program again. This time the message displays on the console.
You can create more than one script in a blend file. To do this, click the ADD NEW button. A new, blank text window, titled TEXT.001, displays. Enter a line of code
print "Message from Outer Space"
Press Alt-P and check the console. The message displays.
If you save the blend file (Control-W), all the text windows are saved. You can also save individual text windows by selecting the Save button from the Text window, or pressing Alt-S. Python files should be saved with an extension of .py.
I hope this gives you a good level of comfort with Blender's Python programming environment. I plan to do more tutorials on how to use Python in Blender. There is a lot to cover, much more than can be done in a 10 minute video. Happy Blending!
Subscribe to:
Posts (Atom)