How to remove the old dirt shader from materials via Coffee/Python?


#1

I’ve have several older project files which contain several materials which used the old “dirt” shader in their diffusion channel. When I try to render the files with Netrender they all stop with “missing texture” errors.

So I’ve been manually going through the materials, clearing the dirt shader from the diffusion channel and disabling the channel.

I have hundreds of project files with several materials in each project so I’ve been trying to automate the process and after a few hours I haven’t gotten very far. Basic scripting allows me to disable the diffusion channel but not clear the “Dirt” material-

So I’m trying to clear the texture in the diffusion channel and disable the channel on the selected materials- or just delete/remove the missing dirt shader from the scene.

I’ve been trying to use “RemovePlugin” in Python as I know the plugin id= 1011136 to no avail as I don’t really know what I’m doing :curious:

If anyone wants to point me in the right direction or offer some help I would really appreciate it! Thanks.


#2

Using this code from Cineversity I’m able to list all the mats in a scene- I can see the “dirt” shader in there- what function do I use to remove the “Dirt” shader from each material?


#3

Right after print shader.GetName()
Paste this :

if shader.GetName()=="Dirt-or-whatever-the-shader's-name-is":
 	shader.Remove()

That should do the job.

d


#4

Thank you so much Douwe!

That saved me hundreds of hours as I have over 800 shots to do this do- I’ll give you a credit in the film I’m using this for- thanks again!

And if anyone else needs to do this here is the code- I’m deleting “Dirt”

import c4d, os
 
############################################################
# recursive function where we do stuff to the shaders
############################################################
def shadertree(shader):
    # Loop through the BaseList
    while(shader):
         
        # This is where you do stuff
        print shader.GetName()
        if shader.GetName()=="Dirt":
            shader.Remove()
        # If it's a bitmap, we'll look at the filename
        if shader.GetType() == c4d.Xbitmap:
            filename = shader[c4d.BITMAPSHADER_FILENAME]
            print filename
            # for instance we can set the filename to just the file part
            filename = os.path.basename(filename)
            shader[c4d.BITMAPSHADER_FILENAME] = filename
         
        # Check for child shaders & recurse
        if shader.GetDown(): shadertree(shader.GetDown())
        # Get the Next Shader
        shader = shader.GetNext()
         
############################################################
# main function
############################################################
def main():
    # Get the first material
    mat = doc.GetFirstMaterial()
    # Loop through materials
    while(mat):
        # Get the first shader
        # Note - this is a 4D list - you've gotta GetDown
        shd = mat.GetFirstShader()
        # Use our recursive function to parse the shader tree
        shadertree(shd)
        # Get the Next material
        mat = mat.GetNext()

#5

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.