0
$\begingroup$

I was making an addon which required a feature to select a material in an enum property. This is part of the code which I wrote to generate the enum property.

def GenerateProperty():
  def getMaterialList(self,context):
    _materials = []
    for i in range(0,len(bpy.data.materials)):
      mat = bpy.data.materials[i]
      _materials.append((str(i),mat.name,''))
    return _materials
  bpy.types.Scene.Materials = bpy.props.EnumProperty(name="Materials", items=getMaterialList)

The items of the enum is dynamically updated while each clicking event. The result ends up like this:

Screenshot

Everything works well until I add a material with Chinese characters. Now the enum property looks like this:

Garbage characters appeared

But my material slot displays these characters properly.

Screenshot of the material slot

I try to print mat.name in python console, and it displays correctly as well. I am now stuck and would appreciate any help!

$\endgroup$
5
  • $\begingroup$ blender.stackexchange.com/questions/216230/… $\endgroup$
    – scurest
    Commented Mar 15, 2023 at 15:38
  • $\begingroup$ @scurest so this seems to be a known bug in enum property? thanks so much for your reply! $\endgroup$
    – Newo Ether
    Commented Mar 15, 2023 at 15:56
  • $\begingroup$ Yup, especially for non latin characters $\endgroup$
    – Gorgious
    Commented Mar 15, 2023 at 16:24
  • $\begingroup$ @Gorgious I tried again by creating a global _material list and manually update that list before "draw" function. That works, and garbage characters no longer appear anymore. $\endgroup$
    – Newo Ether
    Commented Mar 15, 2023 at 17:04
  • $\begingroup$ @Gorgious So it turns out that it's not a problem associated with decoding errors. It is actually a problem of the dynamic enum property. $\endgroup$
    – Newo Ether
    Commented Mar 15, 2023 at 17:07

0

Browse other questions tagged .