intro to bpy scripting

Running Python Scripts

MS Windows

Running python scripts in Blender on Windows is slightly more complicated than Linux, because on Windows you must know the full installation path to blender.exe
on Windows this program is run by:
C:\blender2.79\blender.exe --python 1-move-cube.py

Linux

on Linux this program is run by:
blender --python 1-move-cube.py

Example Script

This script of code will move the cube from it's default location to new location of [1,2,5]
print('hello world')
import bpy

Here i will explain what is bpy ...the Python interface to Blender, everything you can do with a mouse can be done with code and bpy.
bpy.data is the current information inside blender.
bpy.data.objects are all the objects you can reach by name or index, using the brackets symbols after objects and then within the brackets giving a name or number index. Names are quoted while numbers are not.
location on x, y, z
bpy.data.objects["Cube"].location.x = 1
bpy.data.objects["Cube"].location.y = 2
bpy.data.objects["Cube"].location.z = 5

you should see the default cube in blender translated up to
position: [1,2,5]

Comments

Popular Posts