Introduction to Blender Python API 简单介绍Blender Python API 入门篇

in cn •  last year

Introduction to Blender Python API 简单介绍Blender Python API 入门篇。

There's a built in Python interpreter within Blender, which can be used to automate certain work flow in Blender.

Blender 内有个Python的直释器, 可以用来自动化一些流程。


Click at the Editor Type on bottom left, select Python Console.



in the console type:

在控制台,输入["Cube"].location.x += 0.5

where you can basically move the objects around in viewport using the Python commands. The "Cube" is the name of the object of choice which can renamed in object property panel.

基本上你可以用python 指令操作画面上的任何物件。 例子里的Cube是物件名称可以在物件属性编辑栏位编辑。

You can also set all x,y,z coordinates in one single command as such

也可以用以下这个 x,y,z 坐标指令["Cube"] = ( 1,2,1 )

You can also access the vertices, edges and faces of the cube using the following command.


For example, if you want to move 1 single vertex, you can do

例子:假设你想换1个顶点的x 座标["Cube"].data.vertices[0].co.x = 20

Note that the viewport needs to be in Object mode. It will not work in Editable mode



You can use type() function to check the data type of the object. For example

也可以透过 type() 来知道物件的种类。


then you can refer to the following document to see what properties and methods the objects contain.


Using Blender Python to create 3D chart 简单使用Python来制造三维图表

Instead of writing your code in the Python interactive console, you can write it as a script.



we can start with a simple plane as such:



Subdivide into 16x16 grid

分割成 16x16 宫格


Example of simple sine function on 3D plane.


Add more subdivide into the plane to add more resolution,
and create more interesting patterns such as this is


import bpy
from random import *
from mathutils import *
import math

plane_mesh =["Plane"].data
row = 65
col = 65

for i in range(0,row):
    for j in range(0,col):
        v = plane_mesh.vertices[i * col + j].co
        v.z = ( math.sin( (v.x + 0.5)* 2 * math.pi ) * math.sin( (v.y + 0.5) * 2 *  math.pi )  )  * 0.5


If you want, you can even render your output as image.



Have fun!


Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  



@tensaix2j got you a $1.59 @minnowbooster upgoat, nice!
@tensaix2j got you a $1.59 @minnowbooster upgoat, nice! (Image:

Want a boost? Click here to read more!

This post has received a 1.04 % upvote from @drotto thanks to: @banjo.

Congratulations @tensaix2j! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!