3
$\begingroup$

I am trying to fix a bug in the Animation Nodes addon.

The loop nodes has a dynamic EnumProperty and I need to select a default value. But only when the EnumProperty contains Items.

For that I need to know what the value of default is when I don't give it a value. I thought it was an empty string

selectedLoop = bpy.props.EnumProperty(
    items=getStartLoopNodeItems,
    name="Selected Loop",
    default="",
    update=updateActiveL)

but this does not have the same behaviour as if I left out the default parameter

selectedLoop = bpy.props.EnumProperty(
    items=getStartLoopNodeItems,
    name="Selected Loop",
    update=updateActiveL)

Does anyone know what I have to pass to default in order to have the same behaviour?


EDIT: I discovered that when I add the default parameter the EnumProperty is not created apparently because when I try to add it to the layout later it gives me this error:

rna_uiItemR: property not found: mn_LoopCallerNode.selectedLoop
/home/mathieu/.config/blender/2.73/scripts/addons/animation-nodes/nodes/system/mn_loop_caller.py:66
$\endgroup$
  • $\begingroup$ is it just None ? $\endgroup$ – Chebhou Feb 27 '15 at 19:24
  • $\begingroup$ I just tried that after posting my question, but it doesn't seem to work either $\endgroup$ – Mathieu David Feb 27 '15 at 19:25
  • $\begingroup$ it could be "NONE" as the getStartLoopNodeItems() will add this if it's empty $\endgroup$ – Chebhou Feb 27 '15 at 19:51
  • $\begingroup$ Tried but got the same result again. $\endgroup$ – Mathieu David Feb 27 '15 at 20:04
  • $\begingroup$ items[0][0] if that is acceptable, or you can force the getStartLoopNoodeItems() to add the empty item in any case and put it as default $\endgroup$ – Chebhou Feb 27 '15 at 20:04
5
$\begingroup$

There is no default when items is a function (you'll get an error if you try to specify it).

I'll update the doc, this info is missing currently…

Note even with 'static' enums, not specifying the default is not the same as giving "" or None, currently. Not very pythonic, but a consequence of our current C <-> python code.

$\endgroup$
  • $\begingroup$ Ow.. well that sucks. I figured it could be a problem caused by the internal implementation. But now I know for sure :) Thanks a lot for the answer! $\endgroup$ – Mathieu David Feb 27 '15 at 21:17
  • 2
    $\begingroup$ Committed 'fix' for that, now it will be possible to pass 'None' as default and get exact same behavior as if not specifying any default (and updated doc, too). $\endgroup$ – mont29 Feb 27 '15 at 22:10
  • 1
    $\begingroup$ That is great ! Any chance for a possibility to give a default when items are created with a function? Anyway I'm very grateful for your answers, without you I would have gone mad at searching for a fix ;) $\endgroup$ – Mathieu David Feb 28 '15 at 10:28
  • 1
    $\begingroup$ Eh, well, not really… This would have to be a callback too, way overkill imho. Note however that, since, when no default is specified, item with '0' value is used, you are kind of able to control what's default item from items function. $\endgroup$ – mont29 Feb 28 '15 at 10:41
  • $\begingroup$ Perfect, it is not the easiest way but it will do. Many thanks! I really appreciate your time :) $\endgroup$ – Mathieu David Feb 28 '15 at 10:54

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.