0
$\begingroup$

I try to access my materials custom property's value using python. I use the following line of code to do that:

print(bpy.data.materials["MATERIAL NAME"]["CUSTOM PROPERTY NAME"])

what blender returns is this error:

1.0 Traceback (most recent call last): File "/PATH/TO/MY/SCRIPT/script.py", line XY, in KeyError: 'bpy_struct[key]: key "INSTANCING" not found' Error: Python script fail, look in the console for now...

as you can see, before blender throws the error it actually logs my property's value. (1.0)

Since I am looping over all my scene's materials I did this to check if the Custom Property is existing:

hasattr(material, "CUSTOM PROPERTY NAME")

For whatever reason this is returning FALSE for all materials.

Does it have something to do with the fact that the materials I am aiming for are a linked from other .blend files maybe?

For me it's a dead end street for now, so any help would be much appreciated!

$\endgroup$
  • $\begingroup$ @batFINGER that worked for me. Write it as an answer so I can give you credit :) $\endgroup$ – Marten Zander Jan 28 at 19:29
1
$\begingroup$

Unless defined as a bpy.props property hasattr won't work. . Use material.get("prop") or check if "prop" in material.keys()

$\endgroup$
  • $\begingroup$ btw, is it possible to loop over all available keys ? $\endgroup$ – Marten Zander Jan 30 at 14:49
  • 1
    $\begingroup$ for key in material.keys(): value = material[key] $\endgroup$ – batFINGER Jan 30 at 15:18

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.