Setting Up Compositing Part 2

This blog post will go over creating folders for compositing. While compositing comes at the end of the pipeline, it’s actually used in almost every part of the pipeline for simple bash comps to show in review or composite full shots and tweak AOV’s. We’re going to be making a comp directory for each shot and asset which would be a tedious task if done manually. But with the power of Python, it’ll be quick. This will be made even easier by using the Google Sheets API to feed information into just how we want the file structure set up. But we’ll save the Google API introduction for Part 2 and focus on the main script first.

The goal we want to achieve is to make a comp file structure pre-populated with a template for each shot and asset. You will need to make both an asset nuke file template and a generic shot file template. They can be set up however you like, but for this tutorial, we’ll keep it simple and include render outputs for reviews. The template will place the following frames on frame 1000 (studios start frames at 1001, so this won’t mess with our framerange)

This title frame will be in our asset nuke template:


FILE STRUCTURE

film_project parent dir
-- maya project folder
-- comp (the dir structure we're making)
------ rootMedia dir
------ assets dir
------------ assetX dir
---------------- comps dir
-------------------- assetX nuke file
---------------- media dir
---------------- output dir
------------ assetY dir
---------------- comps dir
-------------------- assetY nuke file
---------------- media dir
---------------- output dir
------ shots dir
------------ shotX dir
---------------- comps dir
-------------------- shotX nuke file
---------------- media dir
---------------- output dir
------------ shotY dir
---------------- comps dir
-------------------- shotX nuke file
---------------- media dir
---------------- output dir

WORKFLOW

$ toolName <input argument> <input argument>
$ compDirMaker <asset nuke template file> <shot nuke template file> 


SUDO CODE

# ask the user if they want to create file tree in cwd (current working directory)
# if the answer is yes
    # create parent comp directory in cwd
    # look at list of ASSET_NAMES
    # loops through names in ASSET_NAMES list
        # create a comp dir for each asset
        # add additional dirs (comp, media, output)
        # copy nuke template file to comp dir
        # change name of nuke file to match asset name
    # look at list of SHOT_NAMES
    # loop through names in SHOT_NAMES list
        # create a comp dir for each shot
        # add additional dirs (comp, media, output)
        # copy nuke template file to comp dir
        # use nuke template to create nk files for layout, anim, light and comp 
        # change name of nuke file to match shot name
# if the answer is no
    # close the script




PYTHON CODE

import os
import sys
import shutil
import argparse
def create_dir_structure(nk_template, list, dir_parent):
	'''
	function: loops through shot and asset names to auto create directories
	          and place nuke templates in each comp_file directory
	args: nuke template file path, list of shot/asset names, shot or asset 
	arg type: string, list, string
	'''
	
	for item in list:
		# create directory paths
		comp_parent_dir = "{}/{}/{}_comp".format(cwd, dir_parent, item)
		comp_files_dir = "{}/{}/{}/comp_files".format(cwd, dir_parent, item)
		media_files_dir = "{}/{}/{}/media_files".format(cwd, dir_parent, item)
		output_files_dir = "{}/{}/{}/output_files".format(cwd, dir_parent, item)
		# create directories
		os.mkdir(comp_parent_dir)
		os.mkdir(comp_files_dir)
		os.mkdir(media_files)
		os.mkdir(output_files_dir)
		nk_file_template_rename = "{}/{}_template_v001.nk".format(comp_files_dir, dir_parent)
		# copy nuke template into each comp_files directory
		shutil.copy2(nk_template, nk_file_template_rename)


if __name__ == "__main__":
	#  get directory script is running from
	cwd = os.getcwd()
	
	# ask the user if they want to create file tree in cwd (current working directory)
	answer = raw_input("Create dir structure in:\n{}\n[y/n]".format(cwd))
	# if the answer is yes
	if answer == "y":
		parser = argparse.ArgumentParser(description="Create comp directories with templates")
		parser.add_argument("asset", help="Asset nuke file template")
		parser.add_argument("shot", help="Shot nuke file template")
		args = parser.parse_args()
		asset_list = ["house", "toaster"]
		shot_list = ["s01_s010", "s01_s020"]
		# create directory structure for assets
		create_dir_structure(args.asset_nk_template, asset_list, "asset")
		# create direcotry structure for shots
		create_dir_structure(args.shot_nk_template, shot_list, "shot")
	# if the answer is no, close the script
	if answer == "n":
		sys.exit()