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

相关内容

热门资讯

3分钟了解!新蜜瓜牛牛辅助器(... 3分钟了解!新蜜瓜牛牛辅助器(辅助挂)果然有挂(专业辅助技巧教程)-哔哩哔哩;1、德州新蜜瓜牛牛辅助...
两分钟了解!中至麻将辅牌器购买... 两分钟了解!中至麻将辅牌器购买(辅助挂)确实真的有挂(专业辅助揭秘教程)-哔哩哔哩;大家肯定在之前中...
5分钟了解!多乐跑得快能开挂(... 【福星临门,好运相随】;5分钟了解!多乐跑得快能开挂(辅助挂)真是真的是有挂(专业辅助安装教程)-哔...
第四分钟了解!手机浙江宝宝麻将... 您好,手机浙江宝宝麻将这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在...
第1分钟了解!友友互娱辅助(辅... 第1分钟了解!友友互娱辅助(辅助挂)果然真的有挂(专业辅助插件教程)-哔哩哔哩;一、友友互娱辅助软件...
第四分钟了解!老友十三水开挂(... 第四分钟了解!老友十三水开挂(辅助挂)本来是有挂(专业辅助教你攻略)-哔哩哔哩;老友十三水开挂简单的...
第一分钟了解!星悦麻将怎样设置... 第一分钟了解!星悦麻将怎样设置拿好牌(辅助挂)本然存在有挂(专业辅助普及教程)-哔哩哔哩;1、不需要...
十分钟了解!江苏连云港大宝麻将... 十分钟了解!江苏连云港大宝麻将软件靠谱(辅助挂)原本有挂(专业辅助透明教程)-哔哩哔哩;致您一封信;...
第2分钟了解!阿拉游戏中心可以... 第2分钟了解!阿拉游戏中心可以老是输(辅助挂)真是有挂(专业辅助黑科技教程)-哔哩哔哩,阿拉游戏中心...
两分钟了解!九酷众娱辅助器(辅... 两分钟了解!九酷众娱辅助器(辅助挂)最初是有挂(专业辅助详细教程)-哔哩哔哩;1、让任何用户在无需A...