Converting file format and mass changing shader material

Hi all, I am trying to do a complex converting and replacing of hypershade nodes and I am totally at a lost of how to start off. Please do bear with me as I shall try my best to explain it

Basically, I have a huge model scene that comes with tons of geos and ‘texture’ images in them and they are in the form of surface shader material.
Example. Geo01 --> Assign with surfaceShader01 --> Contains image file in the format of .tga

And so, right now, I am trying to replace surfaceShader material with blinn and convert the file format into .tex
Example. Geo01 --> Assign with blinn01 --> Contains texture file in the format of .tex

I know it may be possible to do it manually one by one, but as the scene file contains near to 100 plus geos and image files for me to convert, are there any codings that can allows me to do it at one shot, without installing any third party apps?

By the way, I chanced upon that I have txmake (file conversion from pixar?), is it a good tool to integrate into it??

For some reasons, I am unable to edit my post, but I just realize I have txmake, a conversion tool from Pixar?

If you’re working with an .ma file, you be able to pull it off with search/replace in a text editor.

[QUOTE=saschaherfort;24856]If you’re working with an .ma file, you be able to pull it off with search/replace in a text editor.[/QUOTE]

I’ll second that response. Even if you did this with a script you’d spend more time writing the script than doing a search&replace. Especially if you know precisely what you are replacing.

I have somewhat search through the office database and I chanced upon this code that my senior did and it is very much similar to what I am trying to achieve.
As it is a proprietary shader, the texture file will be located in <proprietary shader>.Input_Texture[0].inputTextures, example mtlShader.Input_Texture[0].inputTextures

I did some amendments to it, here and there, but it seems that my senior is using json file to extract the information out of the surfaceShader in the scene before applying it and have it convert in the mtlShader.
And he uses txmake to do the conversion of .tga to .tif then to .tex

While it works for me in a sense, are there any ways that I can bypass the json file generation (I do not have any ideas how does the json file comes about)? Meaning to say, have everything done in one shot without it creating any other files etc?


    import os
    import maya.cmds as mc
    import maya.mel as mm
    import pymel.core as pm
    import json
    from PIL import Image
    
    lsSurfShdr = mc.ls(type = 'surfaceShader')
    
    def makeJsonDir():
        tmpJson  = "/user_data/.tmp/tmpJson/"
        
        if not os.path.exists(tmpJson):
            print "Tmp folder does not exists, creating one.
" 
            os.makedirs(tmpJson)
    
    def lsCon(shaders):
        conDict = {}
        for i in shaders:
            con = mc.listConnections('%s.outColor' % i)
            try:
                msh = pm.listConnections(con[1], type = "mesh")[0].longName()
                text = mc.getAttr("%s.fileTextureName" % con[0])
                currentDict = { "twoD" : con, "mesh" : msh, "txtPath" : text}
                conDict[i] = currentDict
            except IndexError:
                pass        
        return conDict
    
    def writeJson():
        makeJsonDir()
        path = "/user_data/.tmp/tmpJson/connectionData.con"
        conData = lsCon(lsSurfShdr)
        toBeSaved = json.dumps(conData, sort_keys = True, ensure_ascii = True, indent = 4)
        f = open(path, 'w')
        f.write(toBeSaved)
        f.close()
        
    def getMtlShader():
        # Command to create the proprietary shader
        createMtl = mm.eval('mtlShader("/hosts/krateh/tools/mtlshaders/mtlGeneric.slo")')
        
    def convertToTexture(inImg, outImg, texImg):
        if not os.path.exists(texImg):
            Image.open(inImg).save(outImg)
            os.system('/apps/Linux64/prman/bin/txmake ' + outImg + ' ' + texImg)
            os.remove(outImg)
            print "done converting " + inImg
        else: 
            pass
    
    def propagate(trans):
        shapes = mc.listRelatives(trans, fullPath = True, shapes = True)
        if len(shapes) == 1:
            mc.rename(shapes,  mc.listRelatives(shapes, p = True)[0] + "_Shape")
        else:
            count = 0
            for s in shapes:
                dup = mc.duplicate(trans)
                ls = mc.listRelatives(dup, fullPath = True, shapes = True)
                i = 0
                for i in xrange(0, len(ls)):
                    if i == count:
                        mc.rename(ls[i], mc.listRelatives(ls[i], p = True)[0] + "_Shape")
                    else:
                        mc.delete(ls[i])
                    i += 1
                count += 1
                
            mc.delete(trans)
    
    def fixTrans():
        sel = mm.eval("SelectAllGeometry;")
        s = mc.ls(sl = True)
        for i in s:
            propagate(i)
        
    def main():
        fixTrans()
        writeJson()
        
        f1 = open("/user_data/.tmp/tmpJson/connectionData.con"
        sort = json.load(f1)
        getMtlShader()
        
        for key, value in sort.iteritems():
            msh = value["mesh"]
            text = value["txtPath"]s
            path = os.path.dirname(text)
    
            f = text.split("/")[-1]
            tifName = os.path.splitext(f)[0] + ".tif"
            texName = os.path.splitext(f)[0] + ".tex"
            
            tifPath = os.path.join(path, tifName)
            texPath = os.path.join(path, texName)
            
            convertText(text, tifPath, texPath)
            
            newTmp = mc.duplicate("mtlGeneric", ic = True)
            mm.eval("setAttr -type \"string\" " + newTmp[0] +  ".Input_Texture[0].inputTextures" "\"" + texPath + "\";")
            mc.rexAssign(msh,  p = "BEAUTY", a = newTmp[0])
            mc.rename(newTmp[0], msh.replace("|", "") + "_GenShdr")

Contents in the Json file:


    {
        "AreaA_0010_1SE": {
            "mesh": "|pansasCity_model_null|area1|Ref3D_2001_2", 
            "twoD": [
                "AreaA_0010_1File", 
                "AreaA_0010_1SG"
            ], 
            "txtPath": "/hosts/gangel/lidar/maya/data/texture.0463.tga"
        }, 
        "AreaB_0110_1SE": {
            "mesh": "|pansasCity_model_null|area1|Ref3D_2001_3", 
            "twoD": [
                "AreaB_0110_1File", 
                "AreaB_0110_1SG"
            ], 
            "txtPath": "/hosts/gangel/lidar/maya/data/texture.0464.tga"
        }
    }

Can moderator kindly help me delete this thread? Thanks!