【Blender开发】UI示例:面板与属性示例

面板与属性示例

【Blender开发】UI示例:面板与属性示例
【Blender开发】UI示例:面板与属性示例

import bpy

bl_info = {
    "name" : "test",
    "author" : "yl",
    "description" : "",
    "blender" : (3, 00, 0),
    "version" : (0, 0, 1),
    "location" : "",
    "warning" : "",
    "category" : "Yuelili",
    "doc_url":"https://yuelili.com"
}

# 自定义类
class MESH_OT_cube_grid(bpy.types.Operator):
    bl_idname="mesh.first_tool"  # ID,必须。命名必须要带,以小写字母,下划线 数字(my_operator.my_class_name)
    bl_label = "Test Operator" # 标签,显示名称
    bl_options = {'REGISTER','UNDO'}

    numX : bpy.props.IntProperty(name="X",default=3)
    numY : bpy.props.IntProperty(name="Y",default=2)

    @classmethod
    def poll(cls,context):
        return True

    def excute(self,context):
        print("excute")
        for i in range(self.numX):
            for j in range(self.numY):
                bpy.ops.mesh.primitive_cube_add(size=2, location=(i * 10 , j * 10,0))

        return {"FINISHED"}

    def invoke(self, context, event):
        self.excute(context)
        print("invoke")
        return {"FINISHED"}

class VIEW3D_PD_cube_grid(bpy.types.Panel):
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "My Panel"
    bl_label = "Grid"

    def draw(self,context):
        self.layout.operator("mesh.first_tool")
        col = self.layout.column(align = True)
        col.prop(context.scene.cycles,"preview_samples")

def mesh_add_menu(self,context):
    self.layout.operator("mesh.first_tool")

def register():
    print("塔塔开")

    # 注册
    bpy.utils.register_class(MESH_OT_cube_grid)
    bpy.utils.register_class(VIEW3D_PD_cube_grid)
    bpy.types.VIEW3D_MT_mesh_add.append(mesh_add_menu)
    ...

def unregister():
    print("已经不用再战斗了")
    #注销
    bpy.utils.unregister_class(MESH_OT_cube_grid)
    bpy.utils.unregister_class(VIEW3D_PD_cube_grid)
    bpy.types.VIEW3D_MT_mesh_add.remove(mesh_add_menu)
    ...

 

给TA充电
共{{data.count}}人
人已充电
BlenderBlender开发

【Blender开发】示例:模拟鼠标移动物体 | MODEL模式

2022-1-12 10:40:36

BlenderBlender开发

【Blender开发】示例:操作项示例 bpy.ops

2022-1-12 10:43:23

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
今日签到
搜索