ChangeRenderOutputPaths Script

From The Foundry MODO SDK wiki
Jump to: navigation, search

This script loops through all render output items and changes their paths. The original filename is appended to the new path. Be sure to include the trailing slash at the end of the new path. C:\New\Path\ C:\New\Path\

The script loops through all items looking for render output items. For each one found, it grabs the original path, uses regular expressions to split out the filename, appends it to the new path, and updates the item’s channel.

# perl
#  Joe Angell, Luxology LLC
#  Copyright (c) 2008 Luxology, LLC. All Rights Reserved.
#  Patents pending.
# Changes the output paths of all render output items
#  in the scene
# Make sure we have our arguments
if( $#ARGV + 1 != 1 ) {
    lxout( "Usage: \ new/output/path/" );
    lxout( "Changes all render output item paths to the provided path with the original filename." );
    lxout( "The argument is the new path, which must include the trailing slash." );
    die( "Missing required new path argument" );
my $filenamePart;
# Get the item count
my $n = lxq( "query sceneservice item.N ?" );
# Loop through the items in the scene, looking for output items
for( $i=0; $i < $n; $i++ ) {
    my $type = lxq( "query sceneservice item.type ? $i" );
    if( $type eq "renderOutput" ) {
        # Get the item ID
        $itemID = lxq( "query sceneservice ? $i" );
        lxout( "Item ID: $itemID" );
        # Select the item
        lx( "select.item $itemID" );
        # Get the original path
        my $originalPath = lxq( " renderOutput\$filename ?" );
        # If the path is empty, skip it
        if( !$originalPath ) {
        # Split the path from the filename using regex
        my @pathParts = split( /\/|\\/, $originalPath );
        if( @pathParts == 0 ) {
            # Nothing to split; path must consist of
            #  just the filename
            $filenamePart = $originalPath;
        } else {
            $filenamePart = $pathParts[ @pathParts - 1 ];
        # Combine the passed in path with the original filename
        $newPath = $ARGV[0] . $filenamePart;
        lx( " renderOutput\$filename {$newPath}" );

# 2013-10-23 Add Edit
#Get the path
argc = lx.arg()
#If could not find the path argument, then exit
if (argc == ""):
	lx.out(" path")
	lx.out("For example, setting the output path is H:\modo\study:")
	lx.out(" H:\\modo\\study\\")
	lx.out("The argument is the new path, which must include the trailing slash.")
	sys.exit("LXe_INVALIDARG:Missing required new path argument")
#Get the item count
n = lx.eval1("query sceneservice item.N ?")
#Loop through the items in the scene, looking for output items
for i in range(n):
	itemType = lx.eval("query sceneservice item.type ? %s" % i)
	if(itemType == "renderOutput"):
                #Get the item ID
		itemID = lx.eval("query sceneservice ? %s" % i)
		lx.out("Item ID:",itemID)
		#Select the item
                #Get the original path
		opath = lx.eval(" renderOutput$filename ?")
                #If the path is empty,then skit it
		if(opath == ""):
                lx.out("Item ID:%s Path: %s" % (itemID,opath))
		#Split the file name from path.
		fileNamePart = opath.split("\\")[-1]
		lx.out("File Name Part is: ",fileNamePart)
		#Separate file name attached to a new path at the end
		newpath = argc + fileNamePart
		lx.out("New Path: ",newpath)
 		#using the new path.
		lx.eval(" renderOutput$filename {%s}" % newpath)

More Information