前言

Blender插件是Blender的利器, 用户可以使用各种插件扩充Blender的功能.

Blender Python插件以bpy.props, bpy.types.Operator, bpy.types.Panel, bpy.types.UILayout, (...)为基础, 通过用户自定义包来实现.

插件要点

  1. 定义操作器
  2. 定义操作器控制面板(或菜单)
  3. 注册/注销操作器和面板

简单实例

bl_info = {
"name": "Move X Axis",
"category": "Object",
} import bpy class ObjectMoveX(bpy.types.Operator):
"""My Object Moving Script""" # blender will use this as a tooltip for menu items and buttons.
bl_idname = "object.move_x" # unique identifier for buttons and menu items to reference.
bl_label = "Move X by One" # display name in the interface.
bl_options = {'REGISTER', 'UNDO'} # enable undo for the operator. def execute(self, context): # execute() is called by blender when running the operator. # The original script
scene = context.scene
for obj in scene.objects:
obj.location.x += 1.0 return {'FINISHED'} # this lets blender know the operator finished successfully. def register():
bpy.utils.register_class(ObjectMoveX) def unregister():
bpy.utils.unregister_class(ObjectMoveX) # This allows you to run the script directly from blenders text editor
# to test the addon without having to install it.
if __name__ == "__main__":
register()

参考

  1. Blender插件之操作器(Operator)实战
  2. Blender之UILayout
  3. Blender插件之Panel
  4. Blender之Property
  5. Addon Tutorial
05-11 17:43