A Warning with regards to the version number
![]() CAUTION : As of version 1.8a, Blender
is no longer restricted by the Ckey, and all of the advanced features,
available at this time (June 21, 2000), have been transferred to the free
version of Blender. Version 1.8a is recognizable by the green donut which
appears in the right corner of the Information Window: Note that some of the Python scripts that
you encounter on the Internet may have been written for an older version
of Blender and may not have been updated by the author yet. Usually, the
version number that the script was written for, will appear in a comment
at the top of the script. For those not yet familiar with Python, comments
are indicated by a line beginning with the symbol "#". Normally, for small
scripts, the required changes to update the script, due to changes in the
Blender / Python module as newer versions of Blender were released, are
minimal and can be easily recognized once you are familiar with the Python
scripting features of Blender.
Since version 1.67, Complete Blender utilizes the Python programming language, to access various objects of the software. It is an interpreted
language halfway between BASIC, C++ and Modula, that is, it consists
of a core to which are added elements, which can be loaded according
to the needs and objectives that the script must perform .
Python works in all of the principal operating systems, in particular, all versions of Windows and Unix, and also: NeXt, BeOS, Mac. It is free and can be redistributed. It is sufficiently simple to be assimulated quickly if some essential concepts are already known. These include : what a list is, how to bind a module to a script, how to differentiate a local or global variable, how to build a function, what an object or a class is, and how to use the functions/methods attached to a particular object... suffice it to say, that it is easy to learn if we already have a good grasp of programming concepts, especially from an object oriented programming perspective. However, the objective of this tutorial is not to explain details of the Python programming language, but rather to provide everybody (and not strictly engineering students, who will forgive the trivial details included in the information) the possibility of learning how to use this tool in Blender. Also, it should be noted, that there are some excellent sites devoted to Blender Python script programming where you will be able to find more elaborate examples. The description of the Python language
itself can be obtained at the following address: http://www.python.org/.
For
the French-speaking people.
Differences
between the Script Window First of all, how does the tool physically present itself? Outside (under Windows) it is a DLL, a dynamically linked library of functions which is in the same directory as the Blender binary file. On the graphic interface level, there are two icons which open two windows devoted to Python:
Alt-s
:
Save a file
Alt-a : Select all of the text
Alt-c : Copy the selection.
Alt-U
:
Undo.
Alt-shift-S
:
Menu
Selection which includes "Jump to line number", very usefull for debugging
the code.
Before writing your own scripts, it would perhaps be simpler to use an already existing script. If you haven't already opened a Script Window, do so now by pressing Shift-F11. 1. Push the Browse Datablock
button 2. Choose OPEN NEW
,
which opens a window in the current directory to load a Python script
file ". py ".
To understand what really occurs, it would
probably be best explained by using an example. Note: In case you have
a file selection window open from the previous discussion, simply press
'Esc' to cancel the Blender operation.
(to obtain a # sign with an European azerty keyboard, refer to: How to make? )
for those using a Windows environment) This script calls upon the Blender module to obtain the contents of an object. The function which makes it possible to carry out this operation, is the function Blender.Object.Get("name") . It is not a standard function of the Python language. Indeed, Python can be supplemented by a series of modules containing new objects. If you recall: an object in object oriented programming, is a set of methods (in fact the function Get() is a method of the Object submodule which is contained by the Blender module ) and data. Thus, it is necessary to begin the script with a line asking the interpreter to load the module containing this function. ie. To load the Blender module, the line "import Blender" is used. If no name of an object is provided as an argument to the function Get() , it returns the entire list of objects which currently exists in memory. To
start the execution of a script
In the above example which is used here, it is the combination of the Alt-P keys which is used to activate the script . It is important to note that this is not the only way to initiate a script. In fact, a script can be related to the execution of an animation. In this case, it is the release of the animation which, in turn, will launch the execution of the script. Display
Python output in the console.
Obviously, if you were expecting to see this list displayed in the current window, there is a good chance that you were disappointed. On the other hand, if you check the contents of the "console" (DOS Window or Shell) you will see that it has been modified. Just push the button shown in the above image to see its content: Another alternative would be to launch
Blender from the console/shell with the following parameters:
blender - p 0 200 640 480 (an easy way borrowed from the article of Strubi
and Cartsen which is at the following address: http://www.blenderbuch.de/tutor/python1/python1_eng.html)
Avoiding
errors due to text editing :
It is important to maintain the horizontal line spacings of the script because Python carries them out one after the other, based upon the level of indentation. The indentations and tabulations indicate to the Python language how it must arrange the instructions to form a subroutine; thus the text:
is carried out without an error, whereas
the text (indented space is indicated in red):
will generate an execution error: ![]() Spaces at the end of the line are also
to be avoided.
All of these concepts are necessary to
control the tool, but are not especially helpful to produce shapes and
pictures. The next page explains how to use Python to modify a square
mesh.
Les questions concernant cette page
peuvent ê tre pos é es sur :
|