Textures renamer script



  • On 02/08/2018 at 01:34, xxxxxxxx wrote:

    Hi guys
    I am completely ignorant of scripts
    I wondered if it was possible to write a script that would change the name of all the textures of a project, and relink them.
    eg:
    wood_diffuse.jpg becomes texture_001.jpg
    wood_reflect.jpg becomes texture_002.jpg
    carpet.jpg becomes texture_003.jpg
    curtain_fabric.png becomes texture_004.png
    .....
    .....
    all this with vray materials, where textures are placed in the VrayAdvBitmap shader

    thanks a lot to everyone



  • On 02/08/2018 at 15:12, xxxxxxxx wrote:

    up



  • On 03/08/2018 at 07:21, xxxxxxxx wrote:

    Hi Zac Davide, first of all, welcome in the PluginCafe forum.

    It's actually not necessary to bump a thread if a day has not passed.

    Regarding your question, take in consideration we can only support c4d related stuff, and give you advice about it.
    But as you may know or not, a vrayMaterial, is nothing more than a MaterialData and a VrayAdvBitmap, is a ShaderData.

    All ShaderData are part of a MaterialData. So with the following script, you will iterate over all the shader within the selected material.
    And change the texture path

    import c4d
      
    # Change the texture path to another one for a VrayAdvBitmap
    def changeTexture(shader) :
        before = "wood_diffuse"
        after = "texture_001"
      
        oldPath = shader[c4d.VRAY_BITMAPCCGAMMA_BITMAP_FILENAME] # Read the current value, again I simply drag and drop the parameter in the consoel to knwo the ID
        newPath = oldPath.replace(before, after) # Replace before value by new value
      
        doc = shader.GetDocument()
        doc.AddUndo(c4d.UNDOTYPE_CHANGE, shader)
        shader[c4d.VRAY_BITMAPCCGAMMA_BITMAP_FILENAME] = newPath # Assign the new value
      
        shader.Message(c4d.MSG_UPDATE)
      
    # Iterate a hierarchy and check if the passed is a VrayAdvBitmap shader
    def recurse_hierarchy(shader) :
        while shader:
            # Check if it's a VrayAdvBitmap, I know the ID by drag and drop a VrayAdvancedShader into the console
            if shader.CheckType(1037364) :
                changeTexture(shader)
            recurse_hierarchy(shader.GetDown())
            shader = shader.GetNext()
      
    # Main function
    def main() :
        mats = doc.GetActiveMaterials()
      
        doc.StartUndo()
        # Iterate over selected material
        for mat in mats:
            recurse_hierarchy(mat.GetFirstShader())
        doc.Endndo()
      
    # Execute main()
    if __name__=='__main__':
        main()
    

    If you have any question please let me know! :)
    Cheers,
    Maxime



  • On 03/08/2018 at 10:12, xxxxxxxx wrote:

    thank you so much MaximeA
    I'll try it immediately, and sorry again for my "precocis bump" :)


Log in to reply