I have a material setup like this:
I want now to copy this material via python, and change the texture images (so these should be real copies) but the nodegroup should be referenced (so all copied materials should use that one nodegroup instance).
I copied the material like this:
def copyObjectFromSelectedWithTemplateMaterial(newObjectName, newMaterialName, noOfObjects):
orig = bpy.context.selected_objects[0]
copy = copyActiveObject()
copy.name = newObjectName
copy.location.y = orig.location.y + 2 * noOfObjects
mat = bpy.data.materials["TemplateMaterial"]
# problem: node group is not linked to original...
copy.active_material = mat.copy()
copy.active_material.name = newMaterialName
bpy.context.collection.objects.link(copy)
return copy
def copyActiveObject(): # real copy, not linked copy
orig = bpy.context.selected_objects[0]
return bpy.data.objects.new("my new object", orig.data.copy())
Unfortunately i don't know how to make the nodegroup just a reference...so just the opposite of clicking the button "make single user". Hope it is understandable.