编写插件:
1.
bl_info = {...}
2.
class Test(bpy.types.Operator):
'''Add a Layout.'''
bl_idname = "object.test_operator_add"
bl_label = "AddOperator"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
print('Add Operator Test')
return {'FINISHED'}
3.
def menu_func(self, context):
self.layout.operator(Test.bl_idname, text="Operator4Test", icon='OUTLINER_OB_LATTICE')
4.
def register():
bpy.utils.register_module(__name__)
# Add " Operator4Test " menu to the "Add" menu.
bpy.types.INFO_MT_add.append(menu_func)
def unregister():
bpy.utils.unregister_module(__name__)
# Remove " Operator4Test " menu from the "Add" menu.
bpy.types.INFO_MT_add.remove(menu_func)
在blender编辑器中选择使用该插件和放弃使用该插件时,系统会调用这两个函数用以增加和移除该菜单
if __name__ == "__main__":
register()
测试插件:
1. 将该插件放到addons目录下
2. 在blender编辑器中选择使用该插件
3. 打开blender编辑器控制台,输入
bpy.ops.object.test_operator_add()
,回车即可查看结果