Working with Maya’s python api – The enum attribute

Here is some information on creating a enum attribute in maya python api.


Let’s start on creating an enum attribute that will work like an optionMenu.

First we create our enum class:

Then we can add our attribute to the class:

Next we can add some ‘fields’ to the attribute. This is where we add the options to our optionMenu:

There,  now we have 5 options available to choose from. When queried, we will get an int in return.

Next let’s set up some options in the MFnEnumAttribute class:

We want to be able to key the option we want, and we want to be able to have current option save to the file.

Last, we need to add our newly created attribute to the node we are working on:

The whole code for this enum attribute:


Next, lets look at how to get at our optionMenu when we need to:

When we want to get at the data, we need to create a dataBlock:

The variable ‘optionMenu_value’ now contains the data we want. We can use it like this:

This is an easy way to add a little option box to our plugin.

Leave a Reply

Your email address will not be published. Required fields are marked *