Set custom project location defined by import clip Name

When creating a new project, after selecting a sequence to import, I’d like to script the project name based on the sequence name I’ve imported, as well as to set a custom location. I guess this is pretty straight forward, but am still in the dark. Thanks in advance.

Have you checked out our Python guide yet? https://borisfx.com/support/documentation/mocha/python/

@martinb might be able to shed some light here too.

Hi Jan, can you give an example of a typical scenario using example names and paths?

When starting a new project in Mocha, I choose the clip I would like to track, eg. X:\Project\Plates\001\001_010\001_010_plate_v001.####.exr.
Still in the New Project window, the Name will default to 001_010_plate_v001 and the location to X:\Project\Plates\001\001_010\results.
I would like to program it that it defaults to ‘planar’ instead of plate and the location to another drive and file structure. eg to Z:\Project\Projectfiles\001\001_010\planar.
This stuff is probably easily changed in an init.py, but I haven’t found a way to change these exact values.

Directly from the interface, changing the project name on the fly in the New Project dialog is not possible, but changing the default output after the project is loaded is.

An alternative would be to create your own project loader instead of using the New Project dialog, which you could either run as a command line script or embed as part of the file menu system.

For example, this (poorly optimised) script takes two command arguements and generates a project file:

  • The clip filename
  • the text in the path you want to replace with the word “planar” (the default being plate)

from mocha.project import *
from PySide2.QtCore import QCoreApplication
import sys, os
import pathlib


class new_managed_project():
    def __init__(self,clip_path,replacement="plate"):
        self.new_clip = Clip(clip_path)
        self.proj = Project(self.new_clip)
        proj_filename = os.path.splitext(clip_path)[0].replace(replacement, "planar")+".mocha"
        new_path = os.path.dirname(clip_path.replace(replacement, "planar"))
        self.proj.set_output_dir(new_path)
        pathlib.Path(new_path).mkdir(parents=True, exist_ok=True)
        self.proj.save_as(proj_filename)

app = QCoreApplication(sys.argv)
args = sys.argv
if args != []:
    if os.path.exists(args[1]):
        path = args[1]
        if len(args) > 2:
            project = new_managed_project(clip_path=path, replacement=args[2])
        else:
            project = new_managed_project(clip_path=path)
    else:
        print("Project file path required")
        exit()

else:
    print("Project file path required")

This would create the ouput directory as ../planar and the filename as ../planar/yourfilenameplanar.mocha

You might want to test this is a safe environment before trying it in production. It hasn’t been tested thoroughly. :slight_smile:

1 Like

Thanks for info and for the script!

No worries. It’s very poorly written as I wanted to get you an example quickly to see how it might work!