How to get all possible EnumProperty values for function parameters

When passing an EnumProperty value to the function parameters, just like with direct assignment, we must always specify the value from the constant list exactly, otherwise, Blender will throw an error.

For example, specifying an icon for a button in the UI we pass the text identifier to the “icon” parameter of the “layout.operator” function.

If it is not correct, Blender throws an error:

TypeError: UILayout.operator(): error with keyword argument “icon” – enum “ICON” not found in (‘NONE’, ‘QUESTION’, ‘ERROR’,…)

All possible identifier values ​​that can be passed in the function parameter can be obtained from the RNA structure.

Let’s define a function that will take three parameters – the type of the object from which the function is called, the name of the function, and the name of the parameter passed to it and will return a list of possible Enum values ​​for this parameter.

Now we can get all the values ​​for the “icon” parameter of the “layout.operator” function:

and always pass the correct value to the “icon” parameter.

* .blend file for my Patreon subscribers

0 0 votes
Article Rating
Notify of
0 Comment
Inline Feedbacks
View all comments