Pixyz Studio Replace Material by selecting Name and not ID


I’m using Pixyz Studio and I wanted to replace a material with another one by selecting the Name of the material and not the ID of the Material.

Do you kown how to that by a script ?

Thanks for your help

mats = material.findMaterialsByProperty("Name", "NameOfYourMaterial")
mat_id = mats[0]

You can find the ID of a material using the function above. Then use that ID to assign that material as needed.

I would make sure the array returned has at least one material ID

original_mats = material.findMaterialsByProperty("Name", "Color #cad1eeff")
new_mats = material.findMaterialsByProperty("Name", "Color #ff0000ff")

if len(original_mats) > 0 and len(new_mats) > 0:
	scene.replaceMaterial(original_mats[0], new_mats[0], [1])