Exemplo n.º 1
0
def main():

    # *********************************************************
    # SET UP SECTION
    suffix = "-source.c4d"  # last part of source C4D file name
    # *********************************************************

    nFiles = 0

    c4d.CallCommand(12305, 12305)  # Show Console...
    c4d.CallCommand(13957)
    # Clear console

    currDoc = c4d.documents.GetActiveDocument()

    rootDir = c4d.storage.LoadDialog(c4d.FILESELECTTYPE_SCENES,
                                     "Please choose a folder",
                                     c4d.FILESELECT_DIRECTORY)

    #dirList=os.listdir(path)

    level1Dirs = getSubdirs(rootDir)
    for level1Dir in level1Dirs:

        #print(level1Dir)
        destPath = os.path.join(rootDir, level1Dir)

        xFiles = getFiles(destPath)
        for xFileName in xFiles:
            xFilePath = os.path.join(rootDir, level1Dir, xFileName)
            filename, file_extension = os.path.splitext(xFilePath)
            #print (xFilePath)
            if xFileName.lower().endswith(suffix):
                print "Converting file " + str(xFileName)
                print ""

                load = documents.LoadFile(xFilePath)

                if not load:
                    print("File" + str(xFilePath) + " not loaded")

                newDoc = documents.GetActiveDocument()
                c4d.CallCommand(12253, 12253)  # Render All Materials
                c4d.CallCommand(12091, 12091)  # Gouraud Shading
                c4d.CallCommand(12149, 12149)  # Frame Default
                c4d.EventAdd()
                nFiles += 1
                #newDoc.SaveDocument()
                c4d.CallCommand(12098)  # Save

                c4d.documents.KillDocument(newDoc)

    print "Files refreshed: " + str(nFiles)

    print "   "
    print "*** Good job! All files have been refreshed. ***"
Exemplo n.º 2
0
def Export2FBX(source_file, do_render):
    loaded = documents.LoadFile(source_file)
    if not loaded:
        return (False, 'LOAD: [Fail] EXPORT: [Fail] RENDER: [Fail]')
    doc = documents.GetActiveDocument()
    doc_name_blocks = doc.GetDocumentName().split('.')
    doc_name = ''
    i = 0
    while i < len(doc_name_blocks) - 1:
        if len(doc_name) > 0:
            doc_name += '.'
        doc_name = doc_name + doc_name_blocks[i]
        i += 1
    dest_file = os.path.join(doc.GetDocumentPath(), doc_name)
    render_status = False
    export_status = False
    if do_render:
        renderThread = RenderFile(doc)
        renderThread.dest_file = '' + dest_file
        renderThread.Start()
        renderThread.End()
        render_status = renderThread.GetStatus()
        if render_status:
            render_status = 'Succ'
        else:
            render_status = 'Fail'
    else:
        render_status = 'Skip'
    exportThread = ExportFile(doc)
    exportThread.dest_file = '' + dest_file
    exportThread.Start()
    exportThread.End()
    export_status = exportThread.GetStatus()
    if export_status:
        export_status = 'Succ'
    else:
        export_status = 'Fail'
    return (True, 'LOAD: [Succ] EXPORT: [{0}] RENDER: [{1}]'.format(
        export_status, render_status))
Exemplo n.º 3
0
def main():
    




    # *****************************************************
    # *****************************************************
    # SET UP SECTION

    rootDir = 'D:\\PROJEKTY\\TON\\FINAL_products\\Export34'
    #rootDir = 'E:\\PROJEKTY_E\\TON\\SDS\\models'
    suffix = "-source.c4d" # last part of source C4D file name
    arrMatNames = ["wm","wood solid","wd","wood weneer","f","fabrics","m","metal","x","misc","af","cane"]
    # *****************************************************
    # *****************************************************



    if not os.path.exists(rootDir):
        print ("Root folder does not exist! Change root folder path in your script")
        ctypes.windll.user32.MessageBoxW(0, "Root folder does not exist! Change root folder path in your script", "Missing folder", 1)
        return

    nFiles = 0
    nFolders = 0
    lenSuffix = len(suffix)
    
    c4d.CallCommand(12305, 12305) # Show Console...
    c4d.CallCommand(13957); # Clear console
    
    currDoc = c4d.documents.GetActiveDocument()
    
    #rootDir=c4d.storage.LoadDialog(c4d.FILESELECTTYPE_SCENES, "Please choose a folder", c4d.FILESELECT_DIRECTORY)
    
    
    #dirList=os.listdir(path)
    
    level1Dirs = getSubdirs(rootDir)
    for level1Dir in level1Dirs:
        nFolders += 1
        #print(level1Dir)
        destPath = os.path.join(rootDir, level1Dir)

        xFiles = getFiles(destPath)
        for xFileName in xFiles:
            xFilePath = os.path.join(rootDir,level1Dir,xFileName)
            filename, file_extension = os.path.splitext(xFilePath)
            #print (xFilePath)
            if xFileName.lower().endswith(suffix):
            
                print "Converting file " + str(xFileName) + "\r"
            
                load = documents.LoadFile(xFilePath)
                
                if not load:
                    print ("File" + str(xFilePath) + " not loaded")
                
                newDoc = documents.GetActiveDocument()
                
                allPolyObj = get_all_objects(newDoc.GetFirstObject(), lambda x: x.CheckType(c4d.Opolygon), [])

                # remove object name material prefixes
                for xObj in allPolyObj:
                    # rename objects - remove material prefix
                    xObjName = xObj.GetName()
                    newObjName = xObjName[xObjName.index('_')+1:]
                    print (newObjName)
                    xObj.SetName(newObjName)
                    
                    # remove SDS tags
                    xTag=xObj.GetTag(c4d.Tsds)
                    if xTag != None:
                        xTag.Remove()
                    
                # change material names
                active_mats = newDoc.GetMaterials()

                for mat in active_mats:
                    matName = mat[c4d.ID_BASELIST_NAME]
                    print (matName)
                    xMatName = ''.join([i for i in matName if not i.isdigit()]) #remove all digits from material name - w0m -> wm, f0 -> f etc.
                    if xMatName in arrMatNames:
                        index = arrMatNames.index(xMatName)
                        newMatName = arrMatNames[index+1]
                        mat[c4d.ID_BASELIST_NAME] = newMatName
                    else:
                       print ("Error: material " + xMatMame + " in file " + xFilerName + "does not have full name in script settings! Please edit script setup settings")
                
                destFileName = xFileName[:-lenSuffix] # remove source file suffix from the file name

                #FBX Export
                newFileName = destFileName +  ".fbx" 
                fpathNew = os.path.join (destPath, newFileName)
                removeFile (fpathNew) #if file exists, delete it
                exportFBX(fpathNew,newDoc)
                
                #OBJ Export
                newFileName = destFileName +  ".obj" 
                newFileNameMTL = destFileName +  ".mtl"
                fpathNew = os.path.join (destPath, newFileName)
                fpathNewMTL = os.path.join (destPath, newFileNameMTL)
                removeFile (fpathNew) #if file exists, delete it
                removeFile (fpathNewMTL) #if MTL file exists, delete it
                exportOBJ(fpathNew,newDoc)
                
                
                #Collada 1.4 Export
                newFileName = destFileName +  ".dae" 
                fpathNew = os.path.join (destPath, newFileName)
                removeFile (fpathNew) #if file exists, delete it
                exportDAE14(fpathNew,newDoc)
                
                #Collada 1.5 Export
                #newFileName = destFileName + "-collada1_5" + ".dae"
                #fpathNew = os.path.join (destPath, newFileName)
                #removeFile (fpathNew) #if file exists, delete it
                #exportDAE15(fpathNew,newDoc)
                
                #3DS Export
                newFileName = destFileName + ".3ds"
                fpathNew = os.path.join (destPath, newFileName)
                removeFile (fpathNew) #if file exists, delete it
                export3DS(fpathNew,newDoc)
                
                #VRML Export
                #newFileName = destFileName + ".wrl"
                #fpathNew = os.path.join (destPath, newFileName)
                #removeFile (fpathNew) #if file exists, delete it
                #exportVRML2(fpathNew,newDoc)
                
                nFiles += 1

                c4d.documents.KillDocument(newDoc)
           
    print ("                ")    
    print ("*** GOOD JOB ***")   
    print ("Folders checked:  " + str(nFolders))
    print ("Files converted:  " + str(nFiles))
    print ("End of conversion")
     
    c4d.EventAdd()
Exemplo n.º 4
0
def main():
    
    c4d.CallCommand(12305, 12305) # Show Console...
    c4d.CallCommand(13957); # Clear console
    
    
    # ***************************************
    # SET UP SECTION
    rootDir = 'D:\\PROJEKTY\\TON\\FINAL_products\\Export35'
    destFolderPath = 'D:\\PROJEKTY\\TON\\FINAL_products\\configurator-FBX-Export35'

    suffix = "-source.c4d" # last part of source C4D file, which will be used to create FBX
    # ****************************************************
    
    nFolders = 0
    nFiles = 0
    
    
    
    if not os.path.exists(rootDir):
        print ("Root folder does not exist! Change root folder path in your script")
        ctypes.windll.user32.MessageBoxW(0, "Root folder does not exist! Change root folder path in your script", "Missing folder", 1)
        return
    
    if not os.path.exists(destFolderPath):
        #print(directory)
        os.makedirs(destFolderPath)
    

    
    
    

    doc = c4d.documents.GetActiveDocument()
    
    level1Dirs = getSubdirs(rootDir)
    for level1Dir in level1Dirs:
        nFolders += 1
        #print(level1Dir)
        #level2Dirs = getSubdirs(os.path.join(rootDir, level1Dir))
        #for level2Dir in level2Dirs:
            #print(level2Dir)
        dirPath = os.path.join(rootDir, level1Dir)
        xFiles = getFiles(dirPath)
        for xFileName in xFiles:
            xFilePath = os.path.join(rootDir,level1Dir,xFileName)
            filename, file_extension = os.path.splitext(xFileName)
            #print (xFilePath)
            if xFileName.endswith(suffix):
                nFiles += 1
                print "Converting file " + str(xFileName)
                print ""
            
                load = documents.LoadFile(xFilePath)
                
                if not load:
                    print ("File" + str(xFilePath) + " not loaded")
                
                doc = documents.GetActiveDocument()
                
                

                # ***************************************************************
                # Search for objects with SDS tag, apply SDS and make it editable
                
                arrPolyToSDS = []
                nObjects = 0
    
                allPolyObj = get_all_objects(doc.GetFirstObject(), lambda x: x.CheckType(c4d.Opolygon), [])
    
                for xObj in allPolyObj:
                    xTag=xObj.GetTag(c4d.Tsds)
            
                    if xTag != None:

                        xTag[c4d.SDSTAG_USE_SDS_STEPS] = True # set USE SDS objects Tags temporarily to true
                        
                        #xTag[c4d.SDSTAG_SUBRAY] = 1
                        #xTag[c4d.SDSTAG_SUBEDITOR] = 1
                        arrPolyToSDS.append(xObj)
                        nObjects += 1
                
                topObj = doc.GetFirstObject()
                objName = topObj.GetName()
            
                
                for x in range(0, nObjects):
                
                    # Create the SDS objects for each object with SDS tag and convert it to polygonal 
                    h = c4d.BaseObject(c4d.Osds) # Create new HyperNURBS
                    h[c4d.SDSOBJECT_SUBEDITOR_CM] = 1 # Set Editor subdivision to 1 (value does not matter as each object has its own SDS value set in SDS tag )
                    h[c4d.SDSOBJECT_SUBDIVIDE_UV] = c4d.SDSOBJECT_SUBDIVIDE_UV_EDGE #(value does not matter as each object has its own SDS value set in SDS tag )
                    h[c4d.SDSOBJECT_SUBRAY_CM] = 1 # Set Render subdivisions - (value does not matter as each object has its own SDS value set in SDS tag )
                    h.SetName('SDS')
                    doc.InsertObject(h)
            
                c4d.EventAdd()
                
                index = 0
                mySDS = get_all_objects(doc.GetFirstObject(), lambda x: x.CheckType(c4d.Osds), [])
                for sds in mySDS:
                    sds.InsertUnder(topObj)
                    xPolyObj = arrPolyToSDS[index]
                    sds.SetName(arrPolyToSDS[index].GetName())
                    xPolyObj.InsertUnder(sds)
                    index += 1
                    
                c4d.EventAdd()
                 
                for sds in mySDS:
                    doc.SetActiveObject(sds,c4d.SELECTION_NEW) 
                    
                    c4d.CallCommand(12236, 12236) # Make Editable
                    c4d.CallCommand(1019951, 1019951) # Delete Without Children
                    #print str(arrPolyToSDS[index].GetName())
                
                
                c4d.EventAdd()
                                
                # **********************************************************************************************
                
                
                
                
                
                # **********************************************************************************************
                #FBX Export
                
                newFileName = xFileName[:-len(suffix)] +  ".fbx" # remove suffix from the FBX file name
                newFileName = newFileName.replace("-", "") #delete - from the FBX name
                fpathNew = os.path.join (destFolderPath, newFileName)
                removeFile (fpathNew) #if file exists, delete it first
                exportFBX(fpathNew,doc)
                #print str("SDS objects: " + str(nObjects))
                #print str("                           ")
                
                c4d.documents.KillDocument(doc)
                # **********************************************************************************************
    

    print ("             ")
    print (" *** GOOD JOB *** ")
    print ("Folders checked:" + str(nFolders))
    print ("Files converted:" + str(nFiles))
def main():
    
    c4d.CallCommand(12305, 12305) # Show Console...
    c4d.CallCommand(13957); # Clear console
    
    
    
    
    # ***************************************
    # SET UP SECTION
    root3dDir = 'D:\\PROJEKTY\\TON\\FINAL_products\\Final_ALL'
    
    csvFilePath = 'D:\\PROJEKTY\\TON\\FINAL_products\\Final_ALL\\ton_SDS_180510.csv'
    suffix = "-source.c4d" # last part of source C4D file name
        
    # ***************************************
    
    
    
    
    
    
    nFolders = 0
    nFiles = 0
    arrCSVLines = []
    
    
    if not os.path.exists(root3dDir):
        print (root3dDir)
        print ("Root folder with 3D files does not exist! Change root folder path in your script")
        ctypes.windll.user32.MessageBoxW(0, "Root folder does not exist! Change root folder path in your script", "Missing folder", 1)
        sys.exit(0)
    
    
    
    
    
    level1Dirs = getSubdirs(root3dDir)
    
    for level1Dir in level1Dirs:
        nFolders += 1
        #print(level1Dir)
        #level2Dirs = getSubdirs(os.path.join(rootDir, level1Dir))
        #for level2Dir in level2Dirs:
            #print(level2Dir)
        dirPath = os.path.join(root3dDir, level1Dir)
        xFiles = getFiles(dirPath)
        for xFileName in xFiles:
            xFilePath = os.path.join(root3dDir,level1Dir,xFileName)
            filename, file_extension = os.path.splitext(xFilePath)
            #print (xFilePath)
            if xFileName.lower().endswith(suffix):         
                #open C4D file
                load = documents.LoadFile(xFilePath)
                    
                if not load:
                    print ("File" + str(xFilePath) + " not loaded")
                    
                doc = documents.GetActiveDocument()
                
                
                # ***************************************************************
                # Search for objects with SDS tag, read SDS value and save to to array
                    
                arrSDS = [] # save all SDS tags and its params to array
                arrSDS.append(level1Dir) # get folder name, where C4D is saved
                    
                allPolyObj = get_all_objects(doc.GetFirstObject(), lambda x: x.CheckType(c4d.Opolygon), [])
        
                for xObj in allPolyObj:
                    xTag=xObj.GetTag(c4d.Tsds)
                
                    if xTag != None:
                        arrSDS.append(xObj.GetName()) #append object name
                        arrSDS.append(xTag[c4d.SDSTAG_SUBRAY]) #append SDS value for rendering
                
                
                c4d.documents.KillDocument(doc) # close document as we do not need it anymore
                
                arrCSVLines.append(arrSDS) # save line with 
                
                #***************************************************************
                
                    
        # go thru array and save lines to CSV file           
        with open(csvFilePath,'wb') as resultFile:
            wr = csv.writer(resultFile, dialect='excel')
            for xLine in arrCSVLines:
                #print xLine
                wr.writerow(xLine)
    
    print ("              ")   
Exemplo n.º 6
0
def main():

    c4d.CallCommand(12305, 12305)  # Show Console...
    c4d.CallCommand(13957)
    # Clear console

    # ***************************************
    # SET UP SECTION
    root3dDir = 'D:\\PROJEKTY\\TON\\FINAL_products\\Export35'

    csvFilePath = 'D:\\PROJEKTY\\TON\\FINAL_products\\Export35\\ton_MAT_info_X_200309.csv'
    suffix = "-source.c4d"  # last part of source C4D file name

    # ***************************************

    nFolders = 0
    nFiles = 0
    arrCSVLines = []
    arrMatCat = []

    if not os.path.exists(root3dDir):
        print(root3dDir)
        print(
            "Root folder with 3D files does not exist! Change root folder path in your script"
        )
        ctypes.windll.user32.MessageBoxW(
            0,
            "Root folder does not exist! Change root folder path in your script",
            "Missing folder", 1)
        return

    level1Dirs = getSubdirs(root3dDir)

    # Create list of all used materials

    for level1Dir in level1Dirs:
        nFolders += 1

        dirPath = os.path.join(root3dDir, level1Dir)
        xFiles = getFiles(dirPath)
        for xFileName in xFiles:
            xFilePath = os.path.join(root3dDir, level1Dir, xFileName)
            filename, file_extension = os.path.splitext(xFilePath)
            #print (xFilePath)
            if xFileName.lower().endswith(suffix):
                #open C4D file
                load = documents.LoadFile(xFilePath)

                if not load:
                    print("File" + str(xFilePath) + " not loaded")

                doc = documents.GetActiveDocument()

                # ***************************************************************
                # Get material prefix for each object

                allPolyObj = get_all_objects(
                    doc.GetFirstObject(), lambda x: x.CheckType(c4d.Opolygon),
                    [])

                for xObj in allPolyObj:
                    # rename objects - remove material prefix

                    xTag = xObj.GetTag(c4d.Ttexture)
                    xObjName = xObj.GetName()
                    if xTag != None:
                        xMat = xTag[c4d.TEXTURETAG_MATERIAL]
                        #print (xObjName)
                        matName = xMat[c4d.ID_BASELIST_NAME]

                        if matName not in arrMatCat:
                            arrMatCat.append(matName)
                            print("Adding " + matName +
                                  " to the list of materials")

                    xObjName = xObj.GetName()
                    prefixObjName = xObjName[:xObjName.index('_')]

                    if matName != prefixObjName:
                        print("             ")
                        print("ERROR: Pleaase chceck file " + xFilePath)
                        print(xFilePath)
                        print(
                            "Object " + xObjName +
                            " prefix is different from material name in its texture tag!"
                        )
                        print("** SCRIPT STOPPED ***             ")
                        return

                    #print (newObjName)

                c4d.documents.KillDocument(
                    doc)  # close document as we do not need it anymore

                #arrCSVLines.append(arrSDS) # save line with

                #***************************************************************

    arrMatCat.sort()
    # Create CSV with list of materials used per object
    arrMatCatX = list(arrMatCat)
    arrMatCatX.insert(0, "Product|Material")
    arrCSVLines.append(arrMatCatX)

    print("             ")
    print("Material list created!")
    print(arrMatCat)
    print("             ")

    for level1Dir in level1Dirs:

        dirPath = os.path.join(root3dDir, level1Dir)
        xFiles = getFiles(dirPath)
        for xFileName in xFiles:

            arrModelMats = list(arrMatCat)
            arrMatIndex = []

            xFilePath = os.path.join(root3dDir, level1Dir, xFileName)
            filename, file_extension = os.path.splitext(xFilePath)
            #print (xFilePath)
            if xFileName.lower().endswith(suffix):
                #open C4D file
                print("Checking file " + xFileName)
                load = documents.LoadFile(xFilePath)

                if not load:
                    print("File" + str(xFilePath) + " not loaded")

                doc = documents.GetActiveDocument()

                # ***************************************************************
                # Get material prefix for each object

                allPolyObj = get_all_objects(
                    doc.GetFirstObject(), lambda x: x.CheckType(c4d.Opolygon),
                    [])

                for xObj in allPolyObj:
                    # rename objects - remove material prefix

                    xTag = xObj.GetTag(c4d.Ttexture)
                    xObjName = xObj.GetName()
                    if xTag != None:
                        xMat = xTag[c4d.TEXTURETAG_MATERIAL]
                        #print (xObjName)
                        matName = xMat[c4d.ID_BASELIST_NAME]

                        i = arrMatCat.index(matName)
                        #print str(i)
                        if i not in arrMatIndex:
                            arrMatIndex.append(i)

                #print (arrMatIndex)
                #print ("           ")
                c4d.documents.KillDocument(
                    doc)  # close document as we do not need it anymore

                for i in xrange(0, len(arrModelMats)):
                    if i in arrMatIndex:
                        arrModelMats[i] = "x"
                    else:
                        arrModelMats[i] = ""

                arrModelMats.insert(0, level1Dir)

                #print (arrModelMats)
                arrCSVLines.append(arrModelMats)  # save line with

                #***************************************************************

    print("             ")
    # go thru array and save lines to CSV file
    with open(csvFilePath, 'wb') as resultFile:
        wr = csv.writer(resultFile, dialect='excel')
        for xLine in arrCSVLines:
            #print xLine
            wr.writerow(xLine)

    print("             ")
    print("CSV File created")
    print("             ")
    print("End of script   ")
Exemplo n.º 7
0
def main():
    document = c4d.documents.GetActiveDocument()
    obj = os.path.dirname(os.path.realpath(__file__)) + os.sep + "1.obj"
    vertDataToObj(obj)
    documents.LoadFile(obj)
Exemplo n.º 8
0
def main():

    c4d.CallCommand(12305, 12305)  # Show Console...
    c4d.CallCommand(13957)
    # Clear console

    # *************************************************************
    # *************************************************************
    # SET UP SECTION

    rootDir = 'D:\\PROJEKTY\\TON\\FINAL_products\\Export35'
    #rootDir = 'E:\\PROJEKTY_E\\TON\\SDS\\models'
    suffix = "-source.c4d"  # last part of source C4D file name
    arrMatNames = [
        "wm", "wood solid", "wd", "wood weneer", "f", "fabrics", "m", "metal",
        "x", "misc", "af", "cane"
    ]
    # ************************************************************
    # ************************************************************

    ver = int(c4d.GetC4DVersion())
    if ver > 19000:
        print(
            "ERROR: You run this script in C4D version " + str(ver) +
            ". Please use C4D version 18 as this script is saving C4D files!")
        #sys.exit(0)
        return

    if not os.path.exists(rootDir):
        print(
            "Root folder does not exist! Change root folder path in your script"
        )
        ctypes.windll.user32.MessageBoxW(
            0,
            "Root folder does not exist! Change root folder path in your script",
            "Missing folder", 1)
        return

    nFiles = 0
    nFolders = 0
    lenSuffix = len(suffix)

    currDoc = c4d.documents.GetActiveDocument()

    #rootDir=c4d.storage.LoadDialog(c4d.FILESELECTTYPE_SCENES, "Please choose a folder", c4d.FILESELECT_DIRECTORY)

    #dirList=os.listdir(path)

    level1Dirs = getSubdirs(rootDir)
    for level1Dir in level1Dirs:
        nFolders += 1
        #print(level1Dir)
        destPath = os.path.join(rootDir, level1Dir)

        xFiles = getFiles(destPath)
        for xFileName in xFiles:
            xFilePath = os.path.join(rootDir, level1Dir, xFileName)
            filename, file_extension = os.path.splitext(xFilePath)
            #print (xFilePath)
            if xFileName.lower().endswith(suffix):
                print "Converting file " + str(xFileName)
                print ""

                load = documents.LoadFile(xFilePath)

                if not load:
                    print("File" + str(xFilePath) + " not loaded")

                newDoc = documents.GetActiveDocument()

                # remove all SDS object tags, rename objects and materials
                allPolyObj = get_all_objects(
                    newDoc.GetFirstObject(),
                    lambda x: x.CheckType(c4d.Opolygon), [])

                for xObj in allPolyObj:
                    # rename objects - remove material prefix
                    xObjName = xObj.GetName()
                    newObjName = xObjName[xObjName.index('_') + 1:]
                    xObj.SetName(newObjName)

                    # remove SDS tags
                    xTag = xObj.GetTag(c4d.Tsds)

                    if xTag != None:
                        xTag.Remove()

                # change material names
                active_mats = newDoc.GetMaterials()

                for mat in active_mats:
                    matName = mat[c4d.ID_BASELIST_NAME]
                    xMatName = ''.join(
                        [i for i in matName if not i.isdigit()]
                    )  #remove all digits from material name - w0m -> wm, f0 -> f etc.
                    if xMatName in arrMatNames:
                        index = arrMatNames.index(xMatName)
                        newMatName = arrMatNames[index + 1]
                        mat[c4d.ID_BASELIST_NAME] = newMatName
                    else:
                        print(
                            "Error: material " + xMatMame + " in file " +
                            xFilerName +
                            "does not have full name in script settings! Please edit script setup settings"
                        )

                #tex = mat[c4d.MATERIAL_COLOR_SHADER] # change channel ID here

                #if tex and tex.GetType() == c4d.Xbitmap:
                #path = tex[c4d.BITMAPSHADER_FILENAME]
                #name = splitext(basename(path))[0] # to include extension use: name = basename(path)
                #doc.AddUndo(c4d.UNDOTYPE_CHANGE_SMALL, mat)
                #mat[c4d.ID_BASELIST_NAME] = name

                #C4D Export - Low Poly
                destFileName = xFileName[:
                                         -lenSuffix]  # remove source file suffix from the file name
                newFileName = destFileName + "-lowpoly.c4d"
                fpathNew = os.path.join(destPath, newFileName)
                removeFile(fpathNew)  #if file exists, delete it
                c4d.documents.SaveDocument(
                    newDoc, fpathNew,
                    c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST,
                    c4d.FORMAT_C4DEXPORT)

                #C4D Export - High Poly
                # Create TOP SDS object and put model as a child
                firstC4DObject = newDoc.GetFirstObject()

                h = c4d.BaseObject(c4d.Osds)  # Create new HyperNURBS
                h[c4d.
                  SDSOBJECT_SUBEDITOR_CM] = 2  # Set Editor subdivision to 1
                h[c4d.SDSOBJECT_SUBDIVIDE_UV] = c4d.SDSOBJECT_SUBDIVIDE_UV_EDGE
                h[c4d.SDSOBJECT_SUBRAY_CM] = 2  # Set Render subdivisions -
                h.SetName('Subdivision Surface')
                newDoc.InsertObject(h)
                c4d.EventAdd()

                firstC4DObject.InsertUnder(h)

                destFileName = xFileName[:
                                         -lenSuffix]  # remove source file suffix from the file name
                newFileName = destFileName + "-highpoly.c4d"
                fpathNew = os.path.join(destPath, newFileName)
                removeFile(fpathNew)  #if file exists, delete it
                c4d.documents.SaveDocument(
                    newDoc, fpathNew,
                    c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST,
                    c4d.FORMAT_C4DEXPORT)

                c4d.documents.KillDocument(newDoc)

    print("Folders:  " + str(nFolders))
    print("End of conversion")

    c4d.EventAdd()

    print "   "
    print "*** Good job! All files have been converted. ***"