2
$\begingroup$

I want to make a custom menu in Blender where I can change certain custom settings (code below).

import bpy

class CustomMenu(bpy.types.Menu):
    bl_label = "Custom Menu"
    bl_idname = "custom.menu"

    def draw(self, context):
        layout = self.layout

        settings = context.blend_data.custom_settings

        layout.row().prop(settings, "type", expand=True)


class CustomSettings(bpy.types.PropertyGroup):
    my_settings = bpy.props.EnumProperty(
        name="My Settings",
        description="Custom Settings",
        items=[
            ('S1', "Setting One", "", 0),
            ('S2', "Setting Two", "", 1),
            ('S3', "Setting Three", "", 2),
        ],
        default='S1'
    )


def register():
    bpy.types.BlendData.custom_settings = bpy.props.PointerProperty(type=CustomSettings)
    bpy.utils.register_class(CustomMenu)


def unregister():
    del bpy.types.BlendData.custom_settings
    bpy.utils.unregister_class(CustomMenu)


if __name__ == "__main__":
    register()

    bpy.ops.wm.call_menu(name=CustomMenu.bl_idname)

When I run this code it gives me this error:

TypeError: UILayout.prop(): error with argument 1, "data" - Function.data expected a AnyType type, not tuple

I'm new to scripting in Blender (I do have some experience with python), and most of the code I copied from examples. I would like to have a better understanding of how these custom settings, the prop() function, and blender types work.

$\endgroup$
1
  • $\begingroup$ Can only add bpy.props properties to ID types eg Scene, Object, Mesh, Armature and bones. $\endgroup$
    – batFINGER
    Apr 9 '19 at 3:30
0
$\begingroup$
import bpy

class CUSTOM_MT_menu(bpy.types.Menu): # Menu name need 'UPPER_CASE_MT_mixed_case'
    bl_label = "Custom Menu"

    def draw(self, context):
        layout = self.layout

        settings = context.scene.custom_settings

        layout.row().prop(settings, "my_settings", expand=True) # Layout.prop(data, 'prop') # show data.prop


class CustomSettings(bpy.types.PropertyGroup):
    my_settings = bpy.props.EnumProperty(
        name="My Settings",
        description="Custom Settings",
        items=[
            ('S1', "Setting One", "", 0),
            ('S2', "Setting Two", "", 1),
            ('S3', "Setting Three", "", 2),
        ],
        default='S1'
    )


def register():
    bpy.utils.register_class(CUSTOM_MT_menu)
    bpy.utils.register_class(CustomSettings) #  CustomSettings need register first
    bpy.types.Scene.custom_settings = bpy.props.PointerProperty(type=CustomSettings) #  not BlendData, need Specify a data type.





def unregister():
    del bpy.types.Scene.custom_settings
    bpy.utils.unregister_class(CustomSettings)
    bpy.utils.unregister_class(CUSTOM_MT_menu)


if __name__ == "__main__":
    register()

    bpy.ops.wm.call_menu(name="CUSTOM_MT_menu")

BlendData cause TypeError: UILayout.prop(): error with argument 1, "data" - Function.data expected a AnyType type, not tuple

$\endgroup$
1
  • 7
    $\begingroup$ Please add an explanation of why this solves the problem so others can learn from this. $\endgroup$
    – Sazerac
    Apr 9 '19 at 1:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.