I have two materials named Source and Target. I want to delete all the current nodes in the Target material, and then copy all the nodes (and their values) from the Source material. The context is that I have another script that will be assigning parameters to the Source material, and will go in a loop that iterators over a list of target material names.
I see that this can be done in the UI by using the Copy Material and Paste Material options in the properties panel down-arrow menu. This uses bpy.ops.material.copy() and bpy.ops.material.paste(). But I cannot figure out how to target these commands by name in a material script. (And given that they are bpy.ops, I assume these commands are mode/context sensitive or something? I’d like this script to work under any circumstances.)
EDIT: I also see that bpy.ops.node.clipboard_copy() and paste can be used to copy selected nodes and paste to active material, but this still has the bpy.ops problems.
Is there another way to copy the node setup? Or override one material’s node tree data with another? Or can anyone confirm that I have to use the bpy.ops route, and how I would go about targeting it to the correct material? I’ve never used bpy.ops commands before, only read about them.