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$
1
  • $\begingroup$ @batFINGER that worked for me. Write it as an answer so I can give you credit :) $\endgroup$ Commented Jan 28, 2019 at 19:29

1 Answer 1

2
$\begingroup$

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

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.