2
$\begingroup$

I'm playing around with pie menus in blender. I used the default pie menu template and customized it to suit. But now I have four custom properties on a model and I want to edit them with the pie menu. I followed along one of Sebastians Konig's tutorials but he only used very basic tools like smooth shading etc. He simply right clicked > edit source, but doing that on my custom shaders takes me to this:

row.prop(rna_item, '["%s"]' % escape_identifier(key), text="")

And doing that to any of my custom properties leads me to the same place. How can I access the custom properties and put them into my pie menu?

Here is my code:

import bpy
from bpy.types import Menu

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


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()
        # operator_enum will just spread all available options
        # for the type enum of the operator on the pie
        pie.prop(context.object.data, '["00_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$

It appears you are right clicking view source in the custom property in the UI. Copy data_path will give you the path, eg. ["prop"] where the property name is prop. In the material properties panel the rna_item will be the active material, in the object, the context.object, in the data context.object.data, in the scene context.scene etc.

The code you are seeing is setup to handle the different object types that can have a custom property. escape_identifier most likely handles garbage property names.

The pie menu template. A custom property "prop" has been added to the scene. The 'rna_item' equates to context.scene, the key to "prop":

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

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

        pie = layout.menu_pie()
        pie.prop(context.scene, '["prop"]')
        # operator_enum will just spread all available options
        # for the type enum of the operator on the pie
        pie.operator_enum("mesh.select_mode", "type")
$\endgroup$
  • $\begingroup$ Thank you! I have the data path in now, but I'm still a bit confused with the context.something... For 3 of the properties I'm change a node value, and one of them is a bone rotation. What contexts would I use for those? $\endgroup$ – mr-matt Dec 25 '15 at 18:47
  • $\begingroup$ Ok, I found the context in the python tool tip for the custom property, but its not showing up in the pie menu...I've put my full code into the question. $\endgroup$ – mr-matt Dec 25 '15 at 19:10
  • $\begingroup$ Nevermind, got it, turns out it was just context.object! $\endgroup$ – mr-matt Dec 25 '15 at 19:35

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.