Re: [Script] Mysterious error

Date : Mon, 03 May 2004 19:23:32 +0000
To : XSI(at)Softimage.COM
From : "Bernard Lebel" <atyss4si(at)hotmail.com>
Subject : Re: [Script] Mysterious error
All righty, here is the full script.
Remember that it's a work in progress.

Before you get a heart attack at seeing the length, I should explain that the main function (checksequence()) is basically 5 times the same thing (files are stored in a array, the first file is catched, then its name is broken down, then fiiles with different name are added to another array, and so on, until 5 sequences are evaluated).

Attached is a JScript file with txt extention.


Matt: simpler code also works on my machine. Somewhere in my function things get screwed up and I don't know why.



Thanks Bernard


http://www.bernardlebel.com http://www.xsimontreal.com http://www.xsibase.com




From: Bradley Gabe <bgabe(at)ilm.com>
Reply-To: XSI(at)Softimage.COM
To: XSI(at)Softimage.COM
Subject: Re: [Script] Mysterious error
Date: Thu, 29 Apr 2004 10:22:38 -0700

At this point, I can't really help without seeing more of the code in context.

The only other possibility that comes to mind is variable scope. It's possible you have a mistaken "var" declaration somewhere, or that there's overlap in the scope of one of your functions with some aspect of your loop. In the past, I'd found on more than a few occasions that Jscript doesn't always properly handle variable scope automatically between code blocks.

-Brad

Ok I found more to this.

I get the error because the enumerator can't perform the second iteration,
wich confuses me even more. The called function is successful, but then I
get that error for the second collection item.

Duh?




----- Original Message ----- From: "Bernard Lebel" <atyss4si(at)hotmail.com> To: <XSI(at)Softimage.COM> Sent: Thursday, April 29, 2004 12:42 PM Subject: Re: [Script] Mysterious error




1. While you *should* be able to instantiate your enumerator object
within the for() statement, I've never seen it done, I've never done it,
and looking at the enumerator object on the msdn jscript reference site,
they don't do it there either. So maybe try declaring the enumerator
*before* starting the for() loop.

var f = new Enumerator(oFoldersColl2);
for( ;f.atEnd(); f.moveNext() )


No luck, I get the same results doing this.




2. Are you perhaps manipulating objects within the oFoldersColl2
collection during the loop? That could lead to funky results as well.


Not at all! The objects are folders containing files, and the functions
basically evaluates the files to see if there are missing frames in


rendered


sequences. At no point the initial folder collection is changed. The main
function creates arrays to store different sequences contained in the same
folder, and these arrays are sent to another function to test if there are
missing files. I don't see why I'm getting this error though, I'll keep
investigating.



Thanks for the help Bernard



---
Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
unsubscribe xsi




-- Bradley R. Gabe Industrial Light & Magic


_________________________________________________________________ http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
// --------------------------------------------------------------------------
// ----------- The beginning: Create custom prop and objects, collect infos
// --------------------------------------------------------------------------





// ----------- Create custom property set for the user to input the shot infos





// Add custom property to scene root var oProp = activesceneroot.addcustomproperty( "CheckSequence", false );



// Add Sequence parameter
oProp.addparameter( "Sequence", siString, siClassifUnknown, siPersistable, "Sequence", "Sequence", "", null, null, null, null, null );


// Add Plan parameter
oProp.addparameter( "Plan", siString, siClassifUnknown, siPersistable, "Plan", "Plan", "", null, null, null, null, null );


// Add Start parameter
oProp.addparameter( "Start", siInt4, siClassifUnknown, siPersistable, "Start", "Start frame", "", 0, -100, 2000, 0, 100 );


// Add End parameter
oProp.addparameter( "End", siInt4, siClassifUnknown, siPersistable, "End", "End frame", "", 100, 0, 10000, 1, 500 );


// Inspect custom cpset
inspectobj( oProp, "", "Informations sur le plan", siModal, false );



//Collect informations of CheckSequence custom prop
var sInSequence = oProp.parameters( "Sequence" ).value;
var sInPlan = oProp.parameters( "Plan" ).value;
var iStart = oProp.parameters( "Start" ).value;
var iEnd = oProp.parameters( "End" ).value;

// Perform few operations on values so they mean something
var sSequence = "S" + sInSequence;
var sPlan = "P" + sInPlan;
var iCount = iEnd - iStart + 1;



// Get root path
//var sRootPath = "\\\\Sata-nas1500\\FRAME2\\SEQUENCES";

var sRootPath = "C:\\FRAME2\\SEQUENCES";


// Get final path to lookup (basically the shot folder) var sPath = sRootPath + "\\" + sSequence + "\\" + sPlan;




logmessage( "-------------------------------------------------" ); logmessage( "Premier frame du plan: " + iStart ); logmessage( "Dernier frame du plan: " + iEnd ); logmessage( "Nombre de frames attendus: " + iCount ); logmessage( "Dossier du plan: " + sPath ); logmessage( "-------------------------------------------------" );




// ----------- Create collections to store various folders




// The script supports up to 5 sequences in the same shot folder



// Create empty collection to store folders to evaluate
var oFoldersColl = new ActiveXObject( "XSI.Collection" );

// Create empty collection to store folders that contain files
var oFoldersColl2 = new ActiveXObject( "XSI.Collection" );




var fso = new ActiveXObject( "Scripting.FileSystemObject" );





// ----------- Collect shot folder, subfolders and files




if( !fso.folderexists( sPath ) )
{
logmessage( "Il n'y a pas de dossier de rendu pour le plan spécifié.", siError );
}
else
{
// Get shot folder
var oShotFolder = fso.getfolder( sPath );


		// Add shot folder to folder collection
		oFoldersColl.add( oShotFolder );


// Get shot subfolders var oShotSubFolders = oShotFolder.subfolders;

// Check if subfolders were found
if( oShotSubFolders.count < 1 )
{
logmessage( "Il n'y a pas de dossiers dans le dossier du plan spécifié.", siError );
}
else
{
// Enumerate through shot subfolders
for( var y = new Enumerator( oShotSubFolders ); !y.atEnd(); y.moveNext() )
{
var oShotSubFolder = y.item();


					// Get shot subfolder
					var oShotSbFolder = fso.getfolder( oShotSubFolder );

					// Add all shot subfolders to folders collection except poubelle
					if( oShotSbFolder.name != "poubelle" )
					{
						oFoldersColl.add( oShotSbFolder );



						// There are up to 3 more levels down the folder hierarchy
						// We will now add everything we can to the folders collection
						// without commenting every part


var oSubFolders1 = oShotSbFolder.subfolders;

if( oSubFolders1.count > 0 )
{
for( var b = new Enumerator( oSubFolders1 ); !b.atEnd(); b.moveNext() )
{
var oSubFolder1 = fso.getfolder( b.item() );


								oFoldersColl.add( oSubFolder1 );


var oSubFolders2 = oSubFolder1.subfolders;

if( oSubFolders2.count > 0 )
{
for( var c = new Enumerator( oSubFolders2 ); !c.atEnd(); c.moveNext() )
{
var oSubFolder2 = fso.getfolder( c.item() );


										oFoldersColl.add( oSubFolder2 );


var oSubFolders3 = oSubFolder2.subfolders;

if( oSubFolders3.count > 0 )
{
for( var d = new Enumerator( oSubFolders3 ); !d.atEnd(); d.moveNext() )
{
var oSubFolder3 = fso.getfolder( d.item() );


												oFoldersColl.add( oSubFolder3 );
											}
										}
									}
								}
							}
						}
					}
				}
			}
	}





// Check if oFoldersColl collection is empty
if( oFoldersColl.count < 1 )
{
logmessage( "Pour une raison quelquonque, aucun dossier contenant des séquences n'a été trouvé." );
logmessage( "Veuillez contacter votre support technique ou le directeur technique pour de l'aide." );
}
else
{
for( var e = new Enumerator( oFoldersColl ); !e.atEnd(); e.moveNext() )
{
// Get current folder
var oCollFolder = fso.getfolder( e.item() );


			var oFolderFiles = oCollFolder.files;

			// Check if current folder contains files
			if( oFolderFiles.count > 0 )
			{
				oFoldersColl2.add( oCollFolder );
			}
		}


// DEBUG logmessage( oFoldersColl2.count );


// Check if folder with files was found
if( oFoldersColl2.count < 1 )
{
logmessage( "Aucun des dossiers du plan ne contient de fichiers.", siError );
}
else
{
var f = new Enumerator( oFoldersColl2 );
for( ; !f.atEnd(); f.moveNext() )
{
// At last, we are now ready to call the function that will
// evaluate the files contained in the folder.
// Separate sequences will be split, names broken down, and so on.


					// Get current folder
					var oFolder = fso.getfolder( f.item() );

					// DEBUG
					logmessage( oFolder );
					logmessage( oFolder.name );



if( checksequence( oFolder ) != 1 )
{
logmessage( "Pour une raison quelquonque, CheckSequence a échoué. Désolé.", siError );
}
else
{
logmessage( "CheckSequence complété avec succès.", siInfo );
}
}
}
}









// ----------------------------------------------------------------------------
// ----------- Main function: Split collected sequences and file name elements
// ----------------------------------------------------------------------------


/*
DEBUG
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
var sRootPath = "C:\\FRAME2\\SEQUENCES\\S009\\P023\\decor";
var oFolder = fso.getfolder( sRootPath );
checksequence( oFolder, fso );
*/

function checksequence( oFolder, fso )
{



	// ----------- Create collections and arrays to receive sequences




// Create empty collection to store all files in shot folder var oFilesColl = new ActiveXObject( "XSI.Collection" );

	// Create empty array to store all files in shot folder
	var aFilesArr = new Array();




// Create empty arrays to extract name of sequences var aNameArr1 = new Array(); var aNameArr2 = new Array(); var aNameArr3 = new Array(); var aNameArr4 = new Array(); var aNameArr5 = new Array();

// Create empty collections to store individual sequences
var oSeqColl1 = new ActiveXObject( "XSI.Collection" ); // Final sequence collection
var oSeqColl2 = new ActiveXObject( "XSI.Collection" );
var oSeqColl3 = new ActiveXObject( "XSI.Collection" ); // Final sequence collection
var oSeqColl4 = new ActiveXObject( "XSI.Collection" );
var oSeqColl5 = new ActiveXObject( "XSI.Collection" ); // Final sequence collection
var oSeqColl6 = new ActiveXObject( "XSI.Collection" );
var oSeqColl7 = new ActiveXObject( "XSI.Collection" ); // Final sequence collection
var oSeqColl8 = new ActiveXObject( "XSI.Collection" );
var oSeqColl9 = new ActiveXObject( "XSI.Collection" ); // Final sequence collection


	// Create empty arrays to store individual sequences
	var aSeqArr1 = new Array();		// Final sequence array
	var aSeqArr2 = new Array();
	var aSeqArr3 = new Array();		// Final sequence array
	var aSeqArr4 = new Array();
	var aSeqArr5 = new Array();		// Final sequence array
	var aSeqArr6 = new Array();
	var aSeqArr7 = new Array();		// Final sequence array
	var aSeqArr8 = new Array();
	var aSeqArr9 = new Array();		// Final sequence array




var oFiles = oFolder.files;

	for( var e = new Enumerator( oFiles ); !e.atEnd(); e.moveNext() )
	{
		var oFilesItem = e.item();

		var oFile = fso.getfile( oFilesItem );

		// Add files to collection (to be able to add to array)
		oFilesColl.add( oFile );
	}




//============================================================ for( i=0; i<oFilesColl.count; i++ ) { var oFilesCollItem = oFilesColl(i);

		// Add files to array (to be able to use split)
		aFilesArr[i] = oFilesCollItem;
	}

	// Sort array
	XSIUtils.QuickSort( aFilesArr );

	for( j=0; j<aFilesArr.length; j++ )
	{
		var oFilesElem = aFilesArr[j];

		var oFile = fso.getfile( oFilesElem );
		var sFileName = oFile.name;


// Split name components where there is a dot // Returns an array with the file name, // the padding and extention as separate elements.

		aNameArr1 = sFileName.split( /\./ );
	}

	// Get file name without padding and extention
	var sPreName = aNameArr1[0];

	// Iterate again through all-files array to compare sequence names
	for( k = 0; k<aFilesArr.length; k++ )
	{
		var oFilesElm = aFilesArr[k];
		var oFile = fso.getfile( oFilesElm );
		var sName = oFile.name;

		var oMatch = matchfilename( sPreName, sName );

		if( oMatch != 1 )
		{
			oSeqColl2.add( oFile );
		}
			else
			{
				oSeqColl1.add( oFile );
			}
	}
	//============================================================





	//============================================================

	// ----------> Iterate through collection to add to array
	for( n=0; n<oSeqColl1.count; n++ )
	{
		var oSeqItem1 = oSeqColl1(n);

		aSeqArr1[n] = oSeqItem1;
	}

	// ----------> Iterate through collection to add to array
	for( p=0; p<oSeqColl2.count; p++ )
	{
		var oSeqItem2 = oSeqColl2(p);

		aSeqArr2[p] = oSeqItem2;
	}

	// ----------> Iterate through array
	for( l=0; l<aSeqArr1.length; l++ )
	{
		var oSeqElem1 = aSeqArr1[l];

		var oSeqElem1File = fso.getfile( oSeqElem1 );

		if( oSeqElem1File.size < 6000 )
		{
			logmessage( "Frame assumé raté: " + oSeqElem1File );
		}
	}

	// ----------> Iterate through array
	for( m=0; m<aSeqArr2.length; m++ )
	{
		var oSeqElem2 = aSeqArr2[m];

		var oFile = fso.getfile( oSeqElem2 );
		var sFileName = oFile.name;

		aNameArr2 = sFileName.split( /\./ );
	}

	// Get file name without padding and extention
	var sPreName = aNameArr2[0];

	// Iterate again through aSeqArr2 array to compare sequence names
	for( q=0; q<aSeqArr2.length; q++ )
	{
		var oSeqArrElm2 = aFilesArr[q];
		var oFile = fso.getfile( oSeqArrElm2 );
		var sFileName = oFile.name;

		var oMatch = matchfilename( sPreName, sFileName );

		if( oMatch != 1 )
		{
			oSeqColl4.add( oFile );
		}
			else
			{
				oSeqColl3.add( oFile );
			}
	}
	//============================================================





	//============================================================

	// ----------> Iterate through collection to add to array
	for( r=0; r<oSeqColl3.count; r++ )
	{
		var oSeqItem3 = oSeqColl3(r);

		aSeqArr3[r] = oSeqItem3;
	}

	// ----------> Iterate through collection to add to array
	for( s=0; s<oSeqColl4.count; s++ )
	{
		var oSeqItem4 = oSeqColl4(s);

		aSeqArr4[s] = oSeqItem4;
	}

	// ----------> Iterate through array
	for( t=0; t<aSeqArr3.length; t++ )
	{
		var oSeqElem3 = aSeqArr3[t];

		var oSeqElem3File = fso.getfile( oSeqElem3 );

		if( oSeqElem3File.size < 6000 )
		{
			logmessage( "Frame assumé raté: " + oSeqElem3File );
		}
	}

	// ----------> Iterate through array
	for( u=0; u<aSeqArr4.length; u++ )
	{
		var oSeqElem4 = aSeqArr4[u];

		var oFile = fso.getfile( oSeqElem4 );
		var sFileName = oFile.name;

		aNameArr3 = sFileName.split( /\./ );
	}

	// Get file name without padding and extention
	var sPreName = aNameArr3[0];

	// Iterate again through aSeqArr4 array to compare sequence names
	for( v=0; v<aSeqArr4.length; v++ )
	{
		var oSeqArrElm4 = aSeqArr4[v];
		var oFile = fso.getfile( oSeqArrElm4 );
		var sFileName = oFile.name;

		var oMatch = matchfilename( sPreName, sFileName );

		if( oMatch != 1 )
		{
		oSeqColl6.add( oFile );
		}
			else
			{
				oSeqColl5.add( oFile );
			}
	}
	//============================================================





	//============================================================

	// ----------> Iterate through collection to add to array
	for( w=0; w<oSeqColl5.count; w++ )
	{
		var oSeqItem5 = oSeqColl5(w);

		aSeqArr5[w] = oSeqItem5;
	}

	// ----------> Iterate through collection to add to array
	for( x=0; x<oSeqColl6.count; x++ )
	{
		var oSeqItem6 = oSeqColl6(x);

		aSeqArr6[x] = oSeqItem6;
	}

	// ----------> Iterate through array
	for( y=0; y<aSeqArr5.length; y++ )
	{
		var oSeqElem5 = aSeqArr5[y];

		var oSeqElem5File = fso.getfile( oSeqElem5 );

		if( oSeqElem5File.size < 6000 )
		{
			logmessage( "Frame assumé raté: " + oSeqElem5File );
		}
	}

	// ----------> Iterate through array
	for( z=0; z<aSeqArr6.length; z++ )
	{
		var oSeqElem6 = aSeqArr6[z];

		var oFile = fso.getfile( oSeqElem6 );
		var sFileName = oFile.name;

		aNameArr4 = sFileName.split( /\./ );
	}

	// Get file name without padding and extention
	var sPreName = aNameArr4[0];

	// Iterate again through aSeqArr6 array to compare sequence names
	for( a=0; a<aSeqArr6.length; a++ )
	{
		var oSeqArrElm6 = aFilesArr[a];
		var oFile = fso.getfile( oSeqArrElm6 );
		var sFileName = oFile.name;

		var oMatch = matchfilename( sPreName, sFileName );

		if( oMatch != 1 )
		{
			oSeqColl8.add( oFile );
		}
			else
			{
				oSeqColl7.add( oFile );
			}
	}
	//============================================================





	//============================================================

	// ----------> Iterate through collection to add to array
	for( b=0; b<oSeqColl7.count; b++ )
	{
		var oSeqItem7 = oSeqColl7(b);

		aSeqArr7[b] = oSeqItem7;
	}

	// ----------> Iterate through collection to add to array
	for( c=0; c<oSeqColl8.count; c++ )
	{
		var oSeqItem8 = oSeqColl8(c);

		aSeqArr8[c] = oSeqItem8;
	}

	// ----------> Iterate through array
	for( d=0; d<aSeqArr7.length; d++ )
	{
		var oSeqElem7 = aSeqArr7[d];

		var oSeqElem7File = fso.getfile( oSeqElem7 );

		if( oSeqElem7File.size < 6000 )
		{
			logmessage( "Frame assumé raté: " + oSeqElem7File );
		}
	}

	// ----------> Iterate through array
	for( e=0; e<aSeqArr8.length; e++ )
	{
		var oSeqElem8 = aSeqArr8[e];

		var oFile = fso.getfile( oSeqElem8 );
		var sFileName = oFile.name;

		aNameArr5 = sFileName.split( /\./ );
	}

	// Get file name without padding and extention
	var sPreName = aNameArr5[0];

	// Iterate again through aSeqArr6 array to compare sequence names
	for( f=0; f<aSeqArr8.length; f++ )
	{
		var oSeqArrElm8 = aFilesArr[f];
		var oFile = fso.getfile( oSeqArrElm8 );
		var sFileName = oFile.name;

		var oMatch = matchfilename( sPreName, sFileName );

		if( oMatch == 1 )
		{
			oSeqColl9.add( oFile );
		}
	}
	//============================================================





	//============================================================

	// ----------> Iterate through collection to add to array
	for( g=0; g<oSeqColl9.count; g++ )
	{
		var oSeqItem9 = oSeqColl9(g);

		aSeqArr9[g] = oSeqItem9;
	}

	// ----------> Iterate through array
	for( h=0; h<aSeqArr9.length; h++ )
	{
		var oSeqElem9 = aSeqArr9[h];

		var oSeqElem9File = fso.getfile( oSeqElem9 );

		if( oSeqElem9File.size < 6000 )
		{
			logmessage( "Frame assumé raté: " + oSeqElem9File );
		}
	}
	//============================================================

	// DEBUG
	logmessage( "Returning positive result" );
	return(1);
}





// ----------------------------------------------------------------------------
// ----------- Secondary function: Comparing names to match pattern
// ----------------------------------------------------------------------------




function matchfilename( sName, sPreName )
{
	if( sName.match( sPreName ) )
	{
		return(1);
	}
		else
		{
			return(0);
		}
}


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.