I am developping an automated tool which will help my production team send maya files and attached textures to another studio. Everything must be done without any maya install on the user computer, so pure Python only.
After copying the texture files from LOCALproject/sourceimages/assetName to FTPproject/sourceimages/assetName, I need to change the file paths directly into the ASCII .ma file.
I’m stuck there, as I don’t find any way to only change the lines I want to change. For now, my solution is way too long, as I need to copy more than 1M line from the .ma to a new clean ASCII file, with the filePaths changed:
Simplified script to show my solution:
# maASCIIFile_read = open(sceneToCopy, 'r') maASCIIFile_write = open(sceneToSend, 'w+') # maASCIIFile_read.seek(0) # back to first line ASCIIFileLine_l = maASCIIFile_read.readlines() for line in ASCIIFileLine_l: if '/sourceimages/' in line: i = ASCIIFileLine_l.index(line) correctedLine = line.replace(mapPath, relativeMapPath) ASCIIFileLine_l[i] = correctedLine # maASCIIFile_write.writelines(ASCIIFileLine_l) maASCIIFile_read.close() maASCIIFile_write.close()
While this works, it is way too long. I need a fast solution, as I want to be able to handle lots of files.
What would be the best way to do that?