I've got something for you: I made a python script with that creates a custom submenu in the TOPBAR_MT_edit blender menu. It's a layout.prop_menu_enum with multiple choices which items come from a tuple. My question is: how can I execute a command everytime I change the value in this menu?

I need to execute this code as an argument of blender start script with the -P tag.

Here's my code:

#first I create the tuple items for the custom menu
for o in bpy.data.materials:
    if "pav_" in o.name:
        enum_pavi = enum_pavi + ((str(i), real_name, o.name),)
bpy.types.Scene.nomi_pavi = bpy.props.EnumProperty(items = enum_pavi)

#then I draw the custom entry
def draw_item(self, context):
    sc = bpy.context.scene
    layout = self.layout
    layout.prop_menu_enum(sc, "nomi_pavi", text="Seleziona Pavimento")

#here I append my custom menu entry in the topbar/edit menu
def register():

#this is the function that "applies" the changes in my custom menu. How can I execute it automatically on change?
def aggiorna():
    bpy.data.objects['Pavimento'].material_slots[0].material = bpy.data.materials[nm]

if __name__ == "__main__":

I will appreciate any help. As you can see above I'm not a pro developer... not yet ;-)


Your Answer

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

Browse other questions tagged or ask your own question.