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

相关内容

热门资讯

黑科技辅助挂!(Wpk)其实真... 黑科技辅助挂!(Wpk)其实真的是有挂,(Wpk)一直真的有挂,安装教程(有挂技巧);在进入Wpk辅...
黑科技辅助挂!(红龙扑克)都是... 黑科技辅助挂!(红龙扑克)都是是真的有挂,(红龙扑克)竟然真的是有挂,介绍教程(有挂脚本);1、红龙...
黑科技辅助挂!WPk透视辅助,... 黑科技辅助挂!WPk透视辅助,WpK透视有外挂,攻略方法(有挂神器)进入游戏-大厅左侧-新手福利-激...
黑科技辅助挂!AAPOKEr透... 黑科技辅助挂!AAPOKEr透明挂辅助软件,(德州aapoker俱乐部)详细辅助必备教程(有挂系统)...
黑科技辅助挂!(智星德州)切实... 黑科技辅助挂!(智星德州)切实真的有挂,(智星菠萝德州)真是存在有挂,AA德州教程(有挂攻略)1、起...
黑科技辅助挂!(WEPOKE)... 黑科技辅助挂!(WEPOKE)一贯存在有挂,(wepokE)真是是真的有挂,可靠教程(有挂助手);黑...
黑科技辅助挂!来玩德州app辅... 黑科技辅助挂!来玩德州app辅助工具,德扑作弊事件,新版2025教程(有挂系统)一、来玩德州appA...
黑科技辅助挂!智星菠萝德州辅助... 黑科技辅助挂!智星菠萝德州辅助器工具,智星菠萝德州可以开挂,必胜教程(有挂辅助挂)1、下载好智星菠萝...
黑科技辅助挂!(wPK)都是存... 黑科技辅助挂!(wPK)都是存在有挂,(WPK)其实是真的有挂,wepoke教程(有挂辅助器)wep...
黑科技辅助挂!(aAPOKER... 黑科技辅助挂!(aAPOKER)一直是真的有挂,(aapokER)其实真的是有挂,AI教程(有挂工具...