0
$\begingroup$

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?

$\endgroup$
  • 3
    $\begingroup$ What content exactly? Just some file names or something? If you would like to display some files of a folder, you can easily populate them by using an UI list: blender.stackexchange.com/a/30446/31447 $\endgroup$ – brockmann Jun 11 '18 at 13:18
  • $\begingroup$ It's supposed to be a list of File names from some directory (might become multiple directories), displayed without extensions, but only certain filters (like only consider certain extensions, and if there's the same file with multiple extensions only show that once) $\endgroup$ – IARI Jun 11 '18 at 13:38
  • 1
    $\begingroup$ I would suggest a Menu and Operator approach. Similar to templates menu in text editor. $\endgroup$ – batFINGER Jun 11 '18 at 16:18
1
$\begingroup$

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(
    items=[
        ('IDENTIFIER', 'The UI string', 'Tooltip'),
        ('JEMOEDER', 'Je moeder', 'Op je hoofd'),
    ])

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

$\endgroup$
  • $\begingroup$ Does not work for me - the json data stored in the extra property will not use the ID, but an integer is stored instead :( $\endgroup$ – IARI Jun 11 '18 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.