From: Dylan Penhale <dylan@(email surpressed)>
Subject: Modifying maya submit script
   Date: Mon, 18 Apr 2005 03:56:01 -0700
Msg# 887
View Complete Thread (3 articles) | All Threads
Last Next
I want to make a very simple addition to our otherwise standard submit-maya.pl script by adding another box to the input program and passing the user input to the temp mel file. A lot of the users here know mel well enough to pass commands this way and would value this option. By hacking my way through the script and copying submitoptions I thought I could manage it with no Perl skills. Alas I have come unstuck.....

I've got the input box sorted out:
...
inputmultiline "Funky Mel Script:"  "MelOptions"     ""
...



and I think I have managed to declare it:
...
 	my $submitoptions = "";
        my $meloptions    = "";
        my %in;
...



and check to see if it has data:
...
   		if ( $key eq "NeverCpus" && $in{$key} ne "" )
                    { $nevercpus .= (($nevercpus eq "")?"":"\n") .
                               "nevercpus       $in{$key}"; }

               if ( $key eq "MelOptions" && $in{$key} ne "" )
{ $meloptions .= ($meloptions eq "")?$in{$key}:"\n$in{$key}"; }

                if ( $key eq "SubmitOptions" && $in{$key} ne "" )
{ $submitoptions .= ($submitoptions eq "")?$in{$key}:"\n$in{$key}"; }
...



and I have added it to the submit section:
...
 	$cpus           ||= "# no cpus";
        $nevercpus      ||= "# no nevercpus";
        $submitoptions  ||= "# no submit options";
        $meloptions     ||= "# no mel script options";
        $in{ImageDir}   ||= "-";
        $in{ImgCommand} ||= ($G::iswindows?"start /b wperl ":"perl ") .
                           		 "$G::self -imgcommand %04d";
...

but I can't get it to insert into the script:
...
setAttr "mentalrayGlobals.startExtension" $opt{sfrm};
setAttr "mentalrayGlobals.byExtension"    1;

// insert user mel data
$opt{meloptions};

Mayatomr -render -v $opt{MayatomrVerbose} $opt{MayatomrFlags};
...

I get no errors but also get no data. I'm pretty sure I am not using the correct command to insert(call) the data from "meloptions".

To be honest I've probably made a hack job of it... any suggestions where I have gone wrong?

Dylan Penhale
Systems Administrator
Fuel International
65 King Street
Newtown
2042
Sydney
Australia
p. (Tel# suppressed)
f. (Tel# suppressed)


   From: Greg Ercolano <erco@(email surpressed)>
Subject: Re: Modifying maya submit script
   Date: Mon, 18 Apr 2005 10:53:15 -0700
Msg# 889
View Complete Thread (3 articles) | All Threads
Last Next
Dylan Penhale wrote:
I want to make a very simple addition to our otherwise standard submit-maya.pl script by adding another box to the input program and passing the user input to the temp mel file.

	Since the user's input is multiline mel text, what I would
	do is:

		1) prompt for the mel script as you are doing now,
		2) save this mel text into a temp file in the log directory,
		3) slirp that file up from within the render script
		4) inject their code into the temp mel script as needed

	Regarding #2, you have the right code here to compile the
	multiline data into the 'meloptions':

               if ( $key eq "MelOptions" && $in{$key} ne "" )
                        { $meloptions .= ($meloptions eq > "")?$in{$key}:"\n$in{$key}"; }

	And then in the section just above where it submits the job,
	write the "$meloptions" into the log directory:

..
        # CONVERT SPACES TO DEL
        #    Do this so spaces pass across command lines correctly.
        #
        $in{MayaFlags}      =~ s/ /\x7f/g;
        $in{MayatomrFlags}  =~ s/ /\x7f/g;
        $in{VectorizeFlags} =~ s/ /\x7f/g;
        $in{MrayFlags}      =~ s/ /\x7f/g;

	### FUEL DEPOT MODS: START
	# SAVE MEL OPTIONS (IF ANY) TO A FILE IN THE LOG DIRECTORY
	#    The render portion of the script will then load
	#    and inject it into the mel script.
	#
	my $meloptionsfile = "$in{LogDir}/user-meloptions.mel";
	unless ( open(MELOPTS, ">$meloptionsfile") )
	    { print STDERR "Could not save mel options:\n$meloptionsfile: $!\n"; exit(1);
	print MELOPTS $meloptionsfile;
	close(MELOPTS);
	### FUEL DEPOT MODS: END

        my $submit = <<"EOF";
title           $in{JobTitle}
ram             $in{Ram}
..


and I have added it to the submit section:
..
     $cpus           ||= "# no cpus";
        $nevercpus      ||= "# no nevercpus";
        $submitoptions  ||= "# no submit options";
        $meloptions     ||= "# no mel script options";
        $in{ImageDir}   ||= "-";
        $in{ImgCommand} ||= ($G::iswindows?"start /b wperl ":"perl ") .
                                    "$G::self -imgcommand %04d";

	..no, I wouldn't do that.
	That's the section that's interpreting command line arguments,
	and you don't want to pass the entire mel script the user typed in
	as a single command line option.

	Instead, find the section just above where the script's
	temporary mel script is created, load the user's mel options
	from the above saved file back into a variable, then inject
	the script into the temporary mel:

..
sub CreateMrayMel($%)
{
    my ( $melfile, %opt) = @_;

    ### FUEL DEPOT MODS: START

    # LOAD THE USER'S MEL OPTIONS BACK INTO A VARIABLE
    my $meloptions = "";
    my $meloptionsfile = "$ENV{RUSH_LOGDIR}/user-meloptions.mel";
    if ( -d $meloptionsfile ) { $meloptions = CatFile($meloptionsfile); }

    ### FUEL DEPOT MODS: END

    unless ( open(MEL, ">$melfile") )
        { print STDERR "ERROR: $melfile: $!\n"; return(-1); }
    print MEL <<"EOF";

..
mel script contents
..

setAttr "mentalrayGlobals.startExtension" $opt{sfrm};
setAttr "mentalrayGlobals.byExtension"    1;

/// FUEL DEPOT MODS: START

// insert user mel data
$meloptions;

/// FUEL DEPOT MODS: END

Mayatomr -render -v $opt{MayatomrVerbose} $opt{MayatomrFlags};
..

	If you still have trouble, email me your script in its
	current hacked incarnation, and I can help make these mods
	for you.

--
Greg Ercolano, erco@(email surpressed)
Rush Render Queue, http://seriss.com/rush/
Tel: (Tel# suppressed)
Cel: (Tel# suppressed)
Fax: (Tel# suppressed)

   From: Greg Ercolano <erco@(email surpressed)>
Subject: Re: Modifying maya submit script
   Date: Mon, 18 Apr 2005 23:52:22 -0700
Msg# 893
View Complete Thread (3 articles) | All Threads
Last Next
Dylan Penhale wrote:

> Hi Greg
>
> Thanks for your reply. I have added the sections that you added, but must have removed a bracket somewhere in my flailing. I would love to know what it is that I have missed.


Oops -- I had a quite a few typos in my example code.
I made the following mods, and attached the result after testing it..

    a) There's a missing closing brace on this line:

        unless ( open(MELOPTS, ">$meloptionsfile") )
            { print STDERR "Could not save mel options:\n$meloptionsfile: $!\n"; exit(1);
                                                                                         ^^^
       ..that last line should read:

            { print STDERR "Could not save mel options:\n$meloptionsfile: $!\n"; exit(1); }
                                                                                         ^^^
    b) I had the wrong variable name in the file save code; this line:

    print MELOPTS $meloptionsfile;
                  ^^^^^^^^^^^^^^^^

       ..should have read:

    print MELOPTS $meloptions;

    c) This line was changed:

        if ( -d $meloptionsfile ) { $meloptions = CatFile($meloptionsfile); }

       To instead read:

        if ( -e $meloptionsfile ) { $meloptions = CatFile($meloptionsfile); }
             ^^^

    d) I had to change around the $ENV{RUSH_LOGDIR} code to use $ENV{RUSH_LOGFILE}
       instead. So instead of:
...
    my $meloptionsfile = "$ENV{RUSH_LOGDIR}/user-meloptions.mel";
...

    ..it now reads:
...
    my $meloptionsfile = "$ENV{RUSH_LOGFILE}";    # /foo/bar/0001
       $meloptionsfile =~ s%[/\\][^/\\]*$%%;      # /foo/bar
       $meloptionsfile .= "/user-meloptions.mel"; # /foo/bar/user-meloptions.mel
...

    e) And finally, perl was complaining about the $meloptions not being defined
       at line 902, so I declared it here:

...
    if ( defined($ARGV[0]) && $ARGV[0] eq "-submit" )
    {
        # DEFAULTS
        my $project       = "-";
        my $command       = "";
        my $cpus          = "";
        my $nevercpus     = "";
        my $submitoptions = "";
        my $meloptions    = "";            ### <-- ADD THIS LINE
        my %in;
...

I made the above modifications, and ran some tests  and it seems to work..
when I entered the following text into the "Extra Mel Script:" prompt
of the submit form:

	// Hello
	string $foo = "XXXYYYZZZ";
	print ("THIS IS A TEST: " + $foo + "\n");

...here's what the log looked like, showing how the code was injected into
the mel script:

#################################################################################

--------------- Rush 102.42 --------------
--      Host: geneva
--       Pid: 1076
--     Title: TEST
--     Jobid: ontario.30
--     Frame: 0001
--     Tries: 4
--     Owner: erco (1000/100)
-- RunningAs: normal_user
--  Priority: 1
--      Nice: 10
--    Tmpdir: C:/TEMP/.RUSH_TMP.83
--   LogFile: //meade/net/tmp/scenes/test.ma.log/0001
--   Command: perl //meade//net/tmp/submit-maya-mel.pl -render 1 0 //meade/net/tmp/scenes/test.ma //meade/net/tmp - mentalray 5 0 - - - - off
--   Started: Mon Apr 18 23:40:36 2005
------------------------------------------
     MAYAFLAGS=''
     MRAYFLAGS=''
 MAYATOMRFLAGS=''
VECTORIZEFLAGS=''
         DEBUG='off'

MAPPING DRIVE LETTERS
--------------------------------------------
-- I: Not mapped -- Executing: net use I: \\100.100.100.3\indian /persistent:yes
-- P: Not mapped -- Executing: net use P: \\100.100.100.3\pacific /persistent:yes
-- T: Not mapped -- Executing: net use T: \\100.100.100.2\atlantic /persistent:yes
--------------------------------------------

*** MAYA MENTAL RAY ***
  SCENEPATH=//meade/net/tmp/scenes/test.ma
    PROJECT=//meade/net/tmp
   IMAGEDIR=-
   RENDERER=mentalray
  MAYAFLAGS=
BATCHFRAMES=1 (1-1)
 MAXLOGSIZE=0


//////////////////////////////////////////////////////// MRAY MEL SCRIPT: START

// Image dir specified? Use it.
if ( "-" != "-" )
{
    if ( chdir( "-" ) != 0 )
	{ error("chdir(-): failed\n"); }

    // Force Mayatomr to use our ImageDir. -erco 02/09/04
    setAttr "mentalrayGlobals.outp" -type "string" "-";
}

if ( !`pluginInfo -q -l "Mayatomr"` )
    { error("Make sure 'MAYA_PLUG_IN_PATH' set correctly."); }

// Scene file existence check
string $scene = `file -q -sn`;
if ( size( $scene ) == 0 )
    { error ("'"+$scene+"': scene file not found or not specified\n\n"); }

// Initialize Mayatomr globals
miCreateDefaultNodes();

// Init mray globals
setAttr "mentalrayGlobals.startFrame"     1;
setAttr "mentalrayGlobals.endFrame"       1;
setAttr "mentalrayGlobals.byFrame"        1;
setAttr "mentalrayGlobals.startExtension" 1;
setAttr "mentalrayGlobals.byExtension"    1;

/// FUEL DEPOT MODS: START

// insert user mel data
// Hello                                          <--
string $foo = "XXXYYYZZZ";                        <--
print ("THIS IS A TEST: " + $foo + "\n");         <--

/// FUEL DEPOT MODS: END

Mayatomr -render -v 5 ;

[..]

#################################################################################