1
$\begingroup$

I have EnumProperty, and i need an integer number when i select my "Mode"

Now i have:

item = (
    ('Mode 1', "Mode 1", ""),
    ('Mode 2', "Mode 2",""))

but i need:

item = (
    (1, "Mode 1", ""),
    (2, "Mode 2",""))

class MyProperty(bpy.types.PropertyGroup):
    my_menu = EnumProperty(items = item)

but give error

$\endgroup$
3
  • 1
    $\begingroup$ check this reference: docs.blender.org/api/blender_python_api_2_77_1/… $\endgroup$
    – HikariTW
    May 6, 2019 at 14:04
  • 1
    $\begingroup$ As pointed out enum identifiers are type string. Can you elaborate on why you need it to be an int? $\endgroup$
    – batFINGER
    May 6, 2019 at 14:33
  • $\begingroup$ @batFINGER Right, i need integer because this script control parameter , that parameter accept only an integer, but now by Hikariztw i can transform "1" (string) in 1 (Integer) by int("1") $\endgroup$
    – Noob Cat
    May 9, 2019 at 18:44

1 Answer 1

2
$\begingroup$

Since the EnumPropertyItem(bpy_struct) only accept String as identifier, you can use Python built-in int() and str() to convert between String and Integer.

A Quick example:

a = 13
int(str(a)) is 13 # True
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .