We have seen how we can enter a simple instruction in the Python console Blender incorporates in its windows system. This system is useful for testing commands, but it is not usually used to program a sequence of them.
The console also allows us to explore the commands available through the auto-complete , from entering the start command containing functions Blender Python: “bpy”.
Blender has a window to edit text that can serve as “IDE” Programming in Python, including line numbering, using colors to distinguish the syntax and the possibility of automatic autoidentación of long lines of text.
To open the text editing window you can select the corresponding icon (A sheet of a notebook) I button at the lower left corner of any window. This button defines the type of editor containing the window. Select the icon “Text Editor”.
The new window will replace the previous edition and will show its interface with a text area
To start using this window we open an existing file (Open) or create a new one (New). From that moment we will have a cursor in the editing area will allow us to edit text
The interface changes by adding new options, among which include “Run Script” it will allow us to execute the script that we have in this window.
To test the operation add a few lines of code that allow us to create some geometry:
import bpy zval=[0,1,2,3,4,5] for z in zval: bpy.ops.mesh.primitive_torus_add(rotation=(0, 0, 0), location=(0, 0, z)) |
The first line of code, “import bpy”, He added the object library for Python Blender
The second line defines a vector of coordinates that will serve to define the position “z” objects
A loop “for” assign values “invited” a la variable “z” in each cycle of the loop (6 cycles)
The last line, within the loop as it is indented, will create the geometry.
The result of the code execution, pressing the button “Run Script” or by pressing the key combination “alt” + “P” you can see in the picture below: 6 bulls of equal size, with the same coordinates “x” and “and” but different “z”.
To complete the exercise will keep the script in a file. It is important that this file to use the appropriate extension Python scripts that is “py”. For example “Script_1.py”
We can make small variations of this exercise:
- Could you make two loops, one within the other, to generate a “bulls plane”?
- Could you change the bulls spheres?
- Could you make two loops, one within the other, to generate a “plan beads”?
Must be connected to post a comment.