3
$\begingroup$

I'm trying to insert an separator to an EnumProperty like used in the Operator object.select_by_type. This is the Property used by this Operator (blender-2.77a.tar/blender-2.77a/source/blender/makesrna/intern/rna_object.c - it's written in C):

EnumPropertyItem rna_enum_object_type_items[] = {
    {OB_MESH, "MESH", 0, "Mesh", ""},
    OBTYPE_CU_CURVE,
    OBTYPE_CU_SURF,
    {OB_MBALL, "META", 0, "Meta", ""},
    OBTYPE_CU_FONT,
    {0, "", 0, NULL, NULL},
    {OB_ARMATURE, "ARMATURE", 0, "Armature", ""},
    {OB_LATTICE, "LATTICE", 0, "Lattice", ""},
    {OB_EMPTY, "EMPTY", 0, "Empty", ""},
    {0, "", 0, NULL, NULL},
    {OB_CAMERA, "CAMERA", 0, "Camera", ""},
    {OB_LAMP, "LAMP", 0, "Lamp", ""},
    {OB_SPEAKER, "SPEAKER", 0, "Speaker", ""},
    {0, NULL, 0, NULL, NULL}
};

The line {0, "", 0, NULL, NULL} creates a seperator (In Python the tupel is sorted different from the C-one). In Python I can't use a tupel like ("", None, None) within the item-set and a tupel like ("", "", "") creates a new column (described here: https://blenderartists.org/forum/showthread.php?409613-How-to-create-columns-in-operator_menu_enum-SOLVED).

How can I add a seperator to an EnumProperty in Python?

Thanks.

$\endgroup$
1
  • 1
    $\begingroup$ I expect the c-code that generates the menu from that list will add a separator if the value is 0. I don't think we have a way to add a separator through an enum in python, so we have to create a custom menu instead of using prop_menu_enum $\endgroup$
    – sambler
    Dec 30, 2016 at 10:16

1 Answer 1

3
$\begingroup$

From the documentation for 2.9:

When an item only contains 4 items they define (identifier, name, description, number). Separators may be added using None instead of a tuple. For dynamic values a callback can be passed which returns a list in the same format as the static list.

This is conspicuously absent in the documentation for 2.79, so there may not have been an easy way to do it in Python when this question was asked. But for newer versions, you can just use a straight None instead of a tuple.


Indeed, it was added in 2019: T68260.

$\endgroup$

You must log in to answer this question.

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