1
$\begingroup$

What I wanted to do is, using Python, temporarily swap out the existing materials of selected objects, and after I'm done with these objects, reset their material setup back to their original state.

I already have some clue about how to do it using duplicated objects over a different scene with matching names. But I'm wondering if there is a simpler way to do this?

I'd need to store the entire material setup including what material was inside every material slot of the object. Thinking this way I actually have some more ideas now.

I can store the material names in each object's material slot in their original order, and when restoring, I can just loop over the names of materials stored for each objects if those material names will not change. Thanks for any answers, voted close.

$\endgroup$

closed as unclear what you're asking by TeaCrab, Shady Puck, Ray Mairlot, Duarte Farrajota Ramos, cgslav Jul 28 '17 at 19:39

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Have you considered linking materials from an external materials.blend for example? I think you are over complicating this a lot. $\endgroup$ – VRM Jul 27 '17 at 3:46
  • $\begingroup$ @VRM I'm feeling the same. I could just make a copy of these objects and not touch the original objects. Facepalm. $\endgroup$ – TeaCrab Jul 27 '17 at 15:05
2
$\begingroup$

what you need to do is to press the little "F" next to your material that you want to save for later.

This will save the material data block even though it is not assigned to any object. Then you can assign a new material to your object to experiment, and then come back later.

you can also set those by scripting

material.use_fake_user

enter image description here

If you want to swap materials back later via script, you could probably store your original material in the object datablock. If you have multiple materials, it would be a bit more complicated, but you could remember which material slot held which original material.

Checkout how to work with blender datablocks to save custom metadata:

Datablock Documentation

This is how easily you could add your custom metadata to any object:

C.selected_objects[0]['OriginalMaterial'] = "materialName"
# Access it directly in the console
C.selected_objects[0]['OriginalMaterial']
'material'
$\endgroup$
0
$\begingroup$

You could save your .blend file and then duplicate it and re-name it. After you have altered the materials in the duplicate file you could "Append" the original material from the original file. "Append" can be found under the "File" dropdown menu.

It's not uncommon to use a similar method to build a "Library" of materials and even objects.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.