EnumProperty cannot be accessed like data['property_name'] #50702

Closed
opened 2017-02-16 19:19:25 +01:00 by Adam Dominec · 5 comments
Member

System Info
Ubuntu 16.10 Linux version 4.8.0-32-generic (buildd@lcy01-34)

Blender Version
Broken: fc185fb1d2 (newest daily build)

Apart from the classical access data.property_name, all bpy.props can also be accessed like data['property_name']. This allows us to skip an update callback.
The bug is that it does not work until the first modification of the property.

>>> bpy.types.Scene.enum_prop = bpy.props.EnumProperty(items=[('ONE', "1", "One"), ('TWO', "2", "Two")], update=lambda x,y: print("update"))
>>> C.scene['enum_prop']

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
KeyError: 'bpy_struct[key]: key "enum_prop" not found'

Surprisingly enough, __setitem__ can do the job.

>>> C.scene.__setitem__("enum_prop", 'TWO')
>>> C.scene['enum_prop']

'TWO'

**System Info** Ubuntu 16.10 Linux version 4.8.0-32-generic (buildd@lcy01-34) **Blender Version** Broken: fc185fb1d2 (newest daily build) Apart from the classical access `data.property_name`, all `bpy.props` can also be accessed like `data['property_name']`. This allows us to skip an update callback. The bug is that it does not work until the first modification of the property. ``` >>> bpy.types.Scene.enum_prop = bpy.props.EnumProperty(items=[('ONE', "1", "One"), ('TWO', "2", "Two")], update=lambda x,y: print("update")) >>> C.scene['enum_prop'] Traceback (most recent call last): File "<blender_console>", line 1, in <module> KeyError: 'bpy_struct[key]: key "enum_prop" not found' ``` Surprisingly enough, `__setitem__` can do the job. ``` >>> C.scene.__setitem__("enum_prop", 'TWO') >>> C.scene['enum_prop'] 'TWO' ```
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Author
Member

Added subscriber: @emu-3

Added subscriber: @emu-3

Added subscriber: @mont29

Added subscriber: @mont29

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Bastien Montagne self-assigned this 2017-02-20 10:05:09 +01:00

There is no bug at all here, you are confusing to completely different things:

  • Properties define using bpy.props are “real” RNA properties, they behave like built-in native properties of RNA structures. It changes the definition of the class itself, since it’s available in all its instances.
  • Properties defined/accessed with the 'dict' interface are IDProperties (a.k.a. Custom Properties), only usable with some limited type of data (IDs mostly, plus a few other ones like Bone). It only affects an instance of the RNA class, others won't have it.

In your example, C.scene['enum_prop'] is absolutely not an Enum property of the RNA class Scene, but an string IDProperty defined on current scene only.

There is no bug at all here, you are confusing to completely different things: - Properties define using `bpy.props` are “real” RNA properties, they behave like built-in native properties of RNA structures. It changes the definition of the class itself, since it’s available in **all its instances**. - Properties defined/accessed with the 'dict' interface are IDProperties (a.k.a. Custom Properties), only usable with some limited type of data (IDs mostly, plus a few other ones like Bone). It **only affects an instance** of the RNA class, others won't have it. In your example, `C.scene['enum_prop']` is absolutely not an Enum property of the RNA class Scene, but an string IDProperty defined on current scene only.
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#50702
No description provided.