enum_items not working with dynamic EnumProperty #86803
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
6 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#86803
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
System Information
Operating system: Windows 10
Blender Version
Broken: 2.91.2,
5be9ef4177
, master, 2021-01-19Short description of error
When using a callback to populate a (dynamic)
EnumProperty
, theenum_items
property available for thatrna_type
returns an empty collection.Exact steps for others to reproduce the error
Minimal script sample:
Output:
Added subscriber: @Hugo-Aboud
Added subscriber: @JaumeBellet
Issue here is that RNA_property_enum_items_ex function is called with NULL as context.
When calling the callback (to get the value for example), is scaled up from a BPY_context_get() call on bpy_rna.c
Added subscriber: @lichtwerk
Changed status from 'Needs Triage' to: 'Needs User Info'
I can confirm the behavior.
Trying to understand the usecase a bit better though (since these are 'expanded' correctly for the UI and elsewhere):
Why do you need access to these like demonstrated above?
While not as convenient as from 'proper expanded' collection of
EnumPropertyItem
, you could get them directly through the callback, no?See
#86803.blend
The issue came up while I was trying to setup dynamic nested Menus using
context_pointer_set
, as described here.Since the
data
argument must be ofAnyType
I need acess to theEnumPropertyItem
references.The solution for now has been populating the enum items when the annotations are evaluated. However, this can only be done once, not allowing for dynamic content changes.
Changed status from 'Needs User Info' to: 'Needs Triage'
Changed status from 'Needs Triage' to: 'Confirmed'
Interesting usecase, confirming then.
Added subscriber: @ideasman42
Currently
enum_items
only works for static items. - That is a fixed array of items.For C/C++ code both can be set, for Python passing the item as a function makes it impossible
Marking as a TODO since this isn't an error in the code.
Found some other use case for this trying to make a general method to check wheither current enum value is valid to polluting console with errors like below:
WARN (bpy.rna): C:\Users\blender\git\blender-v360\blender.git\source\blender\python\intern\bpy_rna.c:1343 pyrna_enum_to_py: current value '17' matches no enum in 'BIMModelProperties', '', 'relating_type_id'
Idea of the method was:
I guess it still can be done manually by keeping track of each dynamic items generator in the code.