Page 1 of 1

Importing a file - path not valid

Posted: December 6th, 2009, 7:49 pm
by Athor
Alright I can finally post my problems here! (Waited about 4 months for the activation email :cry: )

I have written a file browser for the production I'm currently working on. It allows the compositors to click on the episode, sequence, shots and render version to quickly import the renders.

Image

It has been working fine but a little slow, because I have been using javascript to scan through all the renders in a folder (getFiles function seems really slow), and find out if the there are file sequences in that folder, then put the files into the end panel so a compositor can select them, then import.

So to speed it up I used command prompt to get a directory listing instead, and its a lot faster. The issue now is that when I go to import the file, I am getting an error saying Unable to set "file". Path is not valid" I can't see the full error because the extend script cuts it off. So the full path its trying to access doesn't appear. But if I do an alert of the path its a valid path and works fine.

I have been trying everything I can think of with no success.

This is the section of code giving me issues:

Code: Select all

var selectedFiles = (win.grp.mainBody.filesPnl.fileslistBox.selection);
				var selectedFilesLength = selectedFiles.length;
			
				
				for (var f=0; f<selectedFilesLength; f++)
				{
					var selectedFilesIndex = (win.grp.mainBody.filesPnl.fileslistBox.selection[f].index);
					var theSeq = new ImportOptions()
		
				
					theSeq.file = new File("H:/Episodes/"+ win.grp.mainBody.epPnl.eplistBox.selection.text + "/" + win.grp.mainBody.sqPnl.sqlistBox.selection.text + "/" + win.grp.mainBody.shPnl.shlistBox.selection.text + "/3d/maya/images/" + win.grp.mainBody.imgPnl.imglistBox.selection.text +"/" + firstFilesOriginal[selectedFilesIndex]);
	
			
					var importedFile = app.project.importFile(theSeq);
If I change the line where I define the file to have the file name at the end instead of getting it from an array it works:

Code: Select all

theSeq.file = new File("H:/Episodes/"+ win.grp.mainBody.epPnl.eplistBox.selection.text + "/" + win.grp.mainBody.sqPnl.sqlistBox.selection.text + "/" + win.grp.mainBody.shPnl.shlistBox.selection.text + "/3d/maya/images/" + win.grp.mainBody.imgPnl.imglistBox.selection.text +"/" +" LL02_S03_SH03_LITV04_RGB.0001.tif");
	

I would really appreciate some help because I am stumped!

Re: Importing a file - path not valid

Posted: December 6th, 2009, 11:27 pm
by Athor
Well I figured it out - the result from cmd prompt seemed to put a character at the end of the file name. When I escaped the string there was a %0D at the end. So I have just used this code to get around it:

Code: Select all

escapedFile = escape(sequences[f]);
importFile = escapedFile.slice(0,escapedFile.length-3);
Is there a better way to do it?

Re: Importing a file - path not valid

Posted: December 8th, 2009, 2:41 pm
by lloydalvarez
When I was writing my Immigration script I found that not only is the built in getFiles function very slow as you are pointing out, it also returns the files in random order on some server configurations making it useless for file sequence detection. Like you I ended up working around it although I wrote a new getFiles function using perl which I found is even faster the the unix ls command.

-Lloyd

Re: Importing files

Posted: February 19th, 2010, 12:54 pm
by sbaden
I think that the essence of my question is in this thread but I don't know enough about scripting yet to breakdown what you have and apply to my issue. Any help would be appreciated...


I am prompting the user to select a folder that has MOV's in it. I then want to import all MOV's one by one to replace the current MOV. The syntax I'm using isn't getting a list of MOV's in the folder.

Code: Select all

alert("Please select a folder with MOV's to be converted."); 
	var movLocation = folderGetDialog("Select folder with comps to be converted.");
	
	

var numMovs = movLocation.length;

for (i = 1; i<= numMovs; i++) {

	var movPath = movLocation.items[i];

	var originalMov = new File(movPath);
	
	convertFolder.item(1).replace(originalMov);
	
	
	
	// more script here
	
	
}
When I add an alert to tell me the number of MOV's in the folder it gives me, "undefined".

Re: Importing a file - path not valid

Posted: February 19th, 2010, 1:45 pm
by lloydalvarez
folderGetDialog is deprecated you should use Folder.selectDialog or Folder.selectDlg.

Code: Select all

var movLocation = Folder.selectDialog;
All that does, however, is get you a Folder object, if you want to get an array of the files in that folder you need to use the getFiles() function:

Code: Select all

var filesArray = movLocation.getFiles();
Lastly, the array returned begins at 0 so you need to start your loop at 0.

-Lloyd

Re: Importing a file - path not valid

Posted: February 19th, 2010, 4:46 pm
by sbaden
Thank you Lloyd, would this then work?

Code: Select all


alert("Please select a folder with MOV's to be converted."); 
	var movLocation = Folder.selectDialog("Select folder with comps to be converted.");
	
var filesArray = movLocation.getFiles();

for (i = 0; i<= filesArray.length; i++) {

	var movPath = filesArray[i];

	var originalMov = new File(movPath);
		
	convertFolder.item(1).replace(originalMov);
}

Re: Importing a file - path not valid

Posted: February 19th, 2010, 5:05 pm
by lloydalvarez

Code: Select all

for (i = 0; i<= filesArray.length; i++) {

   var movPath = filesArray[i].fsName;

   var originalMov = new File(movPath);
      
   convertFolder.item(1).replace(originalMov);
      
}

Re: Importing a file - path not valid

Posted: February 19th, 2010, 5:11 pm
by sbaden
Cool. Thanks Lloyd!

A couple questions if you don't mind:

Why Folder.selectDialog instead of folderGetDialog?

And, what does fsName refer to?

Re: Importing a file - path not valid

Posted: February 19th, 2010, 5:29 pm
by lloydalvarez
Why don't you check out the scripting guide. It will answer those questions and so much more :-)

Lloyd

Re: Importing a file - path not valid

Posted: April 2nd, 2010, 9:19 pm
by adamghering
lloyd,

Wondering if you can answer this for me. I have scoured the scripting guide and was wondering if there is any way to call to the preferences in a script. I work with multiprocessing a lot and I am getting tired of switching it from ram preview while working to rendering on output. I want to write a script that will set it to ram preview on startup but but then another one that runs as a pre-process to rendering that sets it to faster rendering. What are your thoughts?

thanks in advance,

Re: Importing a file - path not valid

Posted: April 2nd, 2010, 9:26 pm
by lloydalvarez

Re: Importing a file - path not valid

Posted: April 2nd, 2010, 9:30 pm
by adamghering
nevermind I found it in one of your other posts...thanks though that was quick....need to write something proprietary any way...its for work and I can't purchase or install third party apps or scripts...which sucks because that includes most plugins unless I really battle through the red tape...grrrr. thanks for the help though.

cheers,