populate a dropdown (or prop_search) with a string list

by IARI   Last Updated July 14, 2018 05:15 AM

I want the user to be able to select a string from a list of possible options.

  • The value stored in the extra properties data must be the selected string (not an integer id as with EnumProperty)
  • The list of options is generated dynamically (content depends on the file system).

    [It contains file names from one or multiple directories, restricted to certain extensions, but displayed without extension, whereas duplicate filenames (i.e. different extensions) are only displayed once]

I tried to use prop_search, but it doesn't work - see this question.

What is the best way to achieve this?

Answers 1

You're mistakingly asssuming that an EnumProperty can only hold integers. This works just fine:

import bpy

bpy.types.Object.my_prop = bpy.props.EnumProperty(
        ('IDENTIFIER', 'The UI string', 'Tooltip'),
        ('JEMOEDER', 'Je moeder', 'Op je hoofd'),

For more info, see the bpy.props.EnumProperty API documentation.

dr. Sybren
dr. Sybren
June 11, 2018 16:28 PM

Related Questions

Dynamic EnumProperty for PropertyGroup items

Updated April 20, 2017 08:15 AM

Enum Property callback forces scene update

Updated April 14, 2017 08:15 AM