Blender2.92PythonUseofIntPropertiescrashesaddon”
创始人
2024-12-22 14:30:28
0

在Blender 2.92中使用IntProperties时,会导致插件崩溃。解决方法是使用FloatProperties或EnumProperties代替IntProperties。

以下是使用FloatProperties的示例代码:

import bpy

class MyProperties(bpy.types.PropertyGroup):
    my_int: bpy.props.FloatProperty(
        name="My Int",
        default=0
    )

class MyOperator(bpy.types.Operator):
    bl_idname = "object.my_operator"
    bl_label = "My Operator"

    def execute(self, context):
        props = context.scene.my_properties
        print(props.my_int)
        return {'FINISHED'}

class MyPanel(bpy.types.Panel):
    bl_idname = "OBJECT_PT_my_panel"
    bl_label = "My Panel"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "My Addon"

    def draw(self, context):
        props = context.scene.my_properties
        self.layout.prop(props, "my_int")
        self.layout.operator("object.my_operator", text="Print Int")

classes = (
    MyProperties,
    MyOperator,
    MyPanel
)

def register():
    for cls in classes:
        bpy.utils.register_class(cls)
    bpy.types.Scene.my_properties = bpy.props.PointerProperty(type=MyProperties)

def unregister():
    del bpy.types.Scene.my_properties
    for cls in classes:
        bpy.utils.unregister_class(cls)

if __name__ == "__main__":
    register()

这是使用EnumProperties的示例代码:

import bpy

class MyEnumChoices:
    VALUES = (
        ("A", "Option A", ""),
        ("B", "Option B", ""),
        ("C", "Option C", "")
    )

class MyProperties(bpy.types.PropertyGroup):
    my_int: bpy.props.EnumProperty(
        name="My Int",
        items=MyEnumChoices.VALUES,
        default="A"
    )

class MyOperator(bpy.types.Operator):
    bl_idname = "object.my_operator"
    bl_label = "My Operator"

    def execute(self, context):
        props = context.scene.my_properties
        print(props.my_int)
        return {'FINISHED'}

class MyPanel(bpy.types.Panel):
    bl_idname = "OBJECT_PT_my_panel"
    bl_label = "My Panel"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "My Addon"

    def draw(self, context):
        props = context.scene.my_properties
        self.layout.prop(props, "my_int")
        self.layout.operator("object.my_operator", text="Print Int")

classes = (
    MyProperties,
    MyOperator,
    My

相关内容

热门资讯

透视脚本!德州hhpoker是... 透视脚本!德州hhpoker是真的吗(透视)好像有辅助工具(有挂技巧)-哔哩哔哩1、实时德州hhpo...
推出新举措!wepokerpl... 推出新举措!wepokerplus开挂(透视)好像是有辅助神器(确实有挂)-哔哩哔哩wepokerp...
做出回应!we-poker正规... 做出回应!we-poker正规吗(透视)本来存在有辅助修改器(有人有挂)-哔哩哔哩1、进入游戏-大厅...
透视黑科技!hh poker辅... 透视黑科技!hh poker辅助器先试用(透视)总是真的有辅助神器(确实有挂)-哔哩哔哩1、hh p...
截至发稿!智星德州插件最新版本... 截至发稿!智星德州插件最新版本更新内容详解(透视)其实存在有辅助软件(果真有挂)-哔哩哔哩一、智星德...
随着!wepoker透视最简单... 随着!wepoker透视最简单三个步骤(透视)本来有辅助修改器(确实有挂)-哔哩哔哩1、玩家可以在w...
截至发稿!pokemomo辅助... 截至发稿!pokemomo辅助工具(透视)好像真的是有辅助平台(有挂技巧)-哔哩哔哩1)pokemo...
这一问题亟待解决!拱趴大菠萝挂... 这一问题亟待解决!拱趴大菠萝挂(透视)确实真的是有辅助app(有挂分享)-哔哩哔哩小薇(辅助器软件下...
透视讲解!hhpoker可以控... 透视讲解!hhpoker可以控制吗(透视)果然是有辅助平台(有挂细节)-哔哩哔哩运hhpoker可以...
于此同时!德州真人透视脚本(透... 于此同时!德州真人透视脚本(透视)果然存在有辅助平台(有挂详情)-哔哩哔哩;1、德州真人透视脚本免费...