0
$\begingroup$

I need an explanation how to access and iterate over Materials in Objects. I want to add few Custom Properties in a set of files (I want to import each file, add Properties to every material in that model, then export and move to another file).

I've found this reference https://docs.blender.org/api/3.6/bpy.props.html, but I cannot figure out how it works with Materials, code in there doesn't seem to add anything in Material Custom Properties.

$\endgroup$

1 Answer 1

0
$\begingroup$

Eventually I've found it out. I've looped over materials, attach a new property to material by passing property name in square brackets just after the iterator, then assign a new value.

for mat in bpy.data.materials:
    mat["prop1"] = "value1"
    mat["prop2"] = [1, 2.3, 16,726]

I haven't tried it with multiple objects being present on scene, maybe it will work as well there.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .