Search code examples
pythonmaya

Maya 2017 playblast file problems


i create playblast in maya by script:

mov = cmds.playblast(f=file_name, st=1, et=100,
                     format='qt', compression='H.264', quality=70,
                     widthHeight=(1280, 720), percent=100,
                     forceOverwrite=True, sequenceTime=False, clearCache=True,
                     viewer=False, showOrnaments=True, offScreen=True, fp=4)

its worked. but sometimes its generate error:

# Error: RuntimeError: file <maya console> line 5: Unable to create video track. Check format. # 

Research showed that Maya does not create the file immediately on the specified path. First, it creates a file in the folder:

C:\Users\max\AppData\Local\Temp\movie_2.mov

And after completion copies it to the path you specified to: file_name

And here there is a problem. The fact is that if during the creation of the playlist something happened and the file (movie_2.mov) was blocked - then it is impossible to create a playlist. Previously, I solved this problem simply by changing the file name to which the miscalculation is going. Now Maya does not give the chance to change this name and always considers only in it. You just specify where the file will be rewritten.

As a result, you have to reboot the computer to remove the file lock and continue to be able to work. This is a big problem.

Tell me, maybe all the same you can specify some other way to find the file in case the file is locked for some reason? Or it is possible as that to delete the blocked file?


Solution

  • A solution was found. Since I can not change the file name to which Maya thinks, I change the temp folder name before each new launch.

    import os
    from maya import cmds
    import tempfile
    
    temp_new_dir = tempfile.mkdtemp()
    tempDir = os.environ["TMP"]
    os.environ["TMP"] = temp_new_dir
    try:
        cmds.playblast(...)
    except Exception as e:
        print e
    finally:
        os.environ["TMP"] = tempDir