I have created enum dropdown list to change masking of an object by changing vertex group assigned

# On Enum change i want to trigger this function 
def maskIt (self, context):
    #Do some thing here like bellow
    #bpy.data.objects["Suzanne"].modifiers["Mask"].vertex_group = "Group 2"

Creating Enum dropdown list here

def initSceneProperties(scn):
    bpy.types.Scene.MyEnum = EnumProperty(
        items = [('Group 1', 'Group 1', 'Group 1',1), 
                 ('Group 2', 'Group 2', 'Group 2',2),
                 ('Group 3', 'Group 3', 'Group 3',3)],
        name = "Mask the MESH")
    scn['MyEnum'] = 2

Calling the function



Use the update argument of the EnumProperty.

import bpy

def maskIt(self, context):
    print('called and changed to,', context.scene.MyEnum)

class LayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "Layout Demo"
    bl_idname = "SCENE_PT_layout"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"

    def draw(self, context):
        layout = self.layout
        scene = context.scene
        layout.prop(scene, "MyEnum")

def register():
    bpy.types.Scene.MyEnum = bpy.props.EnumProperty(
        items = [('Group 1', 'Group 1', 'Group 1',1), 
                 ('Group 2', 'Group 2', 'Group 2',2),
                 ('Group 3', 'Group 3', 'Group 3',3)],
        name = "Mask the MESH",
        default = 'Group 1',
        update = maskIt)


def unregister():
    del bpy.types.Scene.MyEnum

if __name__ == "__main__":

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.