Blender插件模板

自制插件模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
bl_info = {
"name": "pyw_tools",
"author": "PYW",
"version": (1, 0),
"blender": (2, 80, 0),
"location": "见视图右边工具栏",
"description": "PYW实用工具",
"warning": "",
"doc_url": "",
"category": "PYW",
}

import bpy # 引入blender-python模块
# ---------------------------------
# 创建类,用于实现功能
class drop2floor(bpy.types.Operator):
bl_idname = "obj.align_to_floor" # 槽值
bl_label = "对齐地面" # 显示名

def execute(self, context): # execute执行类函数
bpy.ops.object.align(
align_mode = 'OPT_1',
relative_to = 'OPT_1',
align_axis = {'Z'})
return{'FINISHED'}

# 创建类,用于显示界面
class drop2floor_UI(bpy.types.Panel):
bl_label = "align_to_floor"
bl_idname = "align_to_floor"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "PYW"

def draw(self,context): # draw绘制类函数
layout = self.layout
# ----------------
row = layout.row()
row.label(text='将物体对齐地面', icon='SHADING_SOLID')
# ----------------
row = layout.row()
row.operator("obj.align_to_floor", icon="PMARKER_SEL") # 信号槽

# 安装模块
def register():
bpy.utils.register_class(drop2floor)
bpy.utils.register_class(drop2floor_UI)

# 卸载模块
def unregister():
bpy.utils.unregister_class(drop2floor)
bpy.utils.unregister_class(drop2floor_UI)

# 测试模块
if __name__=="__main__":
register()