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.

@ChangeRenderOutputPaths.pl C:\New\Path\

@ChangeRenderOutputPaths.py 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
# ChangeRenderOutputPaths.pl
#  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: \@ChangeRenderOutputPaths.pl 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 item.id ? $i" );
        lxout( "Item ID: $itemID" );
 
        # Select the item
        lx( "select.item $itemID" );
 
        # Get the original path
        my $originalPath = lxq( "item.channel renderOutput\$filename ?" );
 
        # If the path is empty, skip it
        if( !$originalPath ) {
            next;
        }
 
        # 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( "item.channel renderOutput\$filename {$newPath}" );
    }
}

#python
#----------------------------------------------------------
# 2013-10-23 Add Edit
#----------------------------------------------------------
 
#Get the path
argc = lx.arg()
 
#If could not find the path argument, then exit
if (argc == ""):
	lx.out("Usage:@ChangeRenderOutputPaths.py path")
	lx.out("For example, setting the output path is H:\modo\study:")
	lx.out("@ChangeRenderOutputPaths.py 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 item.id ? %s" % i)
		lx.out("Item ID:",itemID)
 
		#Select the item
		lx.command("select.item",item=itemID)
 
                #Get the original path
		opath = lx.eval("item.channel renderOutput$filename ?")
 
                #If the path is empty,then skit it
		if(opath == ""):
			continue
 
                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("item.channel renderOutput$filename {%s}" % newpath)

More Information