1
$\begingroup$

I have a simple pie menu and I have it setup to allow the user to change a custom property value. But I don't want the user to have to choose a value, I want it to be an ON/OFF. So I want to make a checkbox and have it shown in the pie menu, then when they select that, it will change the custom property value to what I need it to be. I have tried going through this but its pretty confusing for me. Could someone show me how to do this?

My current code:

import bpy
from bpy.types import Menu

from bpy.props import BoolProperty

# spawn an edit mode selection pie (run while object is in edit mode to get a valid output)

iSight_Camera_Indicator = BoolProperty(
    name = "iSight Camera Indicator Toggle",
    description = "Turns the iSight Camera Indicator ON and OFF",
    default = False
)

class VIEW3D_PIE_template(Menu):
    # label is displayed at the center of the pie menu.
    bl_label = "Macbook_Controller"
    bl_idname = "Object Mode.mc_pie_menu"

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

        pie = layout.menu_pie()




        """
        pie.prop(context.object, '["00_iSight Camera Indicator"]', text="iSight Camera Indicator Toggle")
        pie.prop(context.object, '["01_Dirt and Dust"]', text="Dirt and Dust Toggle")
        pie.prop(context.object, '["03_Menubar and Dock"]', text="Menubar and Dock Toggle")
        pie.prop(context.object, '["04_Screen Rotation"]', text="Screen Rotation")
        """

        pie.prop(Macbook_Controller, "iSight_Camera_Indicator", text="iSight Camera Indicator Toggle")








def register():
    bpy.utils.register_class(VIEW3D_PIE_template)

    wm = bpy.context.window_manager
    km = wm.keyconfigs.addon.keymaps.new(name = "Object Mode")
    kmi = km.keymap_items.new("wm.call_menu_pie", "E", "PRESS").properties.name = "Object Mode.mc_pie_menu"


def unregister():
    bpy.utils.unregister_class(VIEW3D_PIE_template)


if __name__ == "__main__":
    register()

    #bpy.ops.wm.call_menu_pie(name="VIEW3D_PIE_template")
$\endgroup$
2
  • $\begingroup$ Why the linked post is confusing? $\endgroup$
    – p2or
    Commented Dec 25, 2015 at 21:03
  • $\begingroup$ I don't understand how to put it into my pie menu... $\endgroup$
    – mr-matt
    Commented Dec 25, 2015 at 23:01

1 Answer 1

1
$\begingroup$

The boolProperty needs to be registered to a particular type. In the example below I've associated it with a camera (data) type.

bpy.types.Camera.xxx = BoolProperty()

To assign a property to an Object type would use

bpy.types.Object.xxxx = BoolProperty()

Then all objects in the blend file will have the xxxx property. Use bpy.types.Scene for scenes.. etc.

I used code from https://blender.stackexchange.com/a/40793/15543 for the keymap, it's mapped to Alt-E

Restrict bl_idnames to lowercase, no spaces, only one period . for example "object_mode.xxxx_yyyy" not "Object Mode.xxxx_yyyy"

import bpy
from bpy.types import Menu

from bpy.props import BoolProperty

class VIEW3D_PIE_template(Menu):
    # label is displayed at the center of the pie menu.
    bl_label = "Macbook_Controller"
    bl_idname = "object_mode.mc_pie_menu"

    def draw(self, context):
        layout = self.layout
        # get the camera, use a poll method to check no cam
        scene = context.scene
        camera = scene.camera.data
        pie = layout.menu_pie()

        pie.prop(camera, "iSight_Camera_Indicator", text="iSight Camera Indicator Toggle")

def register():
    # register the property to a camera (data) type
    bpy.types.Camera.iSight_Camera_Indicator = BoolProperty(
                    name = "iSight Camera Indicator Toggle",
                    description = "Turns the iSight Camera Indicator ON and OFF",
                    default = False
                                            )
    bpy.utils.register_class(VIEW3D_PIE_template)

    wm = bpy.context.window_manager
    km = wm.keyconfigs.addon.keymaps.new(name = "Window",space_type='EMPTY', region_type='WINDOW')
    kmi = km.keymap_items.new("wm.call_menu_pie", type = "E", alt=True, value = "PRESS")
    kmi.properties.name = "object_mode.mc_pie_menu"

def unregister():
    bpy.utils.unregister_class(VIEW3D_PIE_template)


if __name__ == "__main__":
    register()
    bpy.ops.wm.call_menu_pie(name="object_mode.mc_pie_menu")
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .