I create some lists using EnumProperty. The lists may be empty, because nothing in the lists. Therefore, I get some warning in the console. "RNA Warning: Current value "0" matches no enum in......." How to get rid of the warning in the console? I don't want to add some "NONE" in the lists when the lists are empty.
-
1$\begingroup$ AFAIK enum props are expected to have at least one element. Are they dynamic enums? what is the issue with having a dummy 'NONE' enum when empty? $\endgroup$– batFINGERMay 25, 2018 at 16:23
-
$\begingroup$ Yes, they are dynamic enums. I am using an add-on makehuman. They also have the enums, but they don't show rna warning when the enums are empty. I don't know why my code have rna warning. @batFINGER $\endgroup$– 萌香ちゃんMay 25, 2018 at 16:59
-
2$\begingroup$ Do you have any UI code accessing the empty enums? $\endgroup$– batFINGERMay 25, 2018 at 17:07
-
$\begingroup$ Yes. I create some buttons to import the object on the list. @batFINGER $\endgroup$– 萌香ちゃんMay 25, 2018 at 19:10
2 Answers
You can avoid this problem by adding a dummy to the list e.g. 'NONE'
which will be used if there is nothing else to draw. This way you can also detect if the list is actually drawn/used for the UI:
("NONE", "None", "", 1),
("RED", "Red", "", 2),
("GREEN", "Green", "", 3),
("BLUE", "Blue", "", 4)
No matter what the length of the dynamic list,
This error occurs, when the index is not found in the list
Example -
("NONE", "None", "", 1), # <--- Not start with 0
("RED", "Red", "", 2),
("GREEN", "Green", "", 3),
("BLUE", "Blue", "", 4)
Solution
If you fist display Blue
with 4 index.
Keep the index with Blue
even if index 3 is no longer present
("NONE", "None", "", 1),
("BLUE", "Blue", "", 4) # <--- index 4
Otherwise, you will get error:
("NONE", "None", "", 1),
("BLUE", "Blue", "", 2) # <--- index 2
pyrna_enum_to_py: current value '4' matches no enum in 'Scene'
Note :- We can't change enum active index without property assignment