Highlighted

Script stack loading issues with filenames

New Here ,
Aug 30, 2020

Copy link to clipboard

Copied

Hi, so I have a scrip to stack some files from a folder which works. 

 

var folder = new Folder('D:/RAW Compare/teststack');
var flist1 = folder.getFiles('*.tif');


cTID = function(s) { return cTID[s] || (cTID[s] = app.charIDToTypeID(s)); };
sTID = function(s) { return app.stringIDToTypeID(s); };

const deleteRecursives = true; //delete recursive stacked images once they are finished

function runLoadStack(fileList) {
    var loadLayersFromScript = true;
    // @include 'Load Files into Stack.jsx'
    //var fList = folder.getFiles('*.tif')
	var aFlag = true;
	
	loadLayers.intoStack(fileList, aFlag);
    loadLayers.alignStack = function( stackDoc ){
		selectAllLayers(stackDoc, 0);
	}

    
}

 

And I have another script to save a resulting tiff file which works. 

function saveNewTiff(fin){
	var doc = app.activeDocument;
	var fileName = File.decode(doc.name);
	var n = fileName.lastIndexOf(".");
	if (n > 0) fileName = fileName.substr(0, n);
	var d = new Date();
	if (fin==true){filename="FINAL_STACK_";}
	fileName += "_" + ("00" + d.getHours()).slice(-2) + "_" + ("00" + d.getMinutes()).slice(-2)+"_"+("00" + d.getSeconds()).slice(-2) + ".tif";
	fileName = folder + "/" + fileName
	//saveTiff(fileName)
	//alert(folder+fileName);
	return saveTiff(fileName);
}

function saveTiff(filename){
	tiffFile = new File(filename);
	tiffSaveOptions = new TiffSaveOptions();   
	tiffSaveOptions.embedColorProfile = true;   
	tiffSaveOptions.alphaChannels = true;   
	tiffSaveOptions.layers = true;  
	tiffSaveOptions.imageCompression = TIFFEncoding.NONE;  
	//alert(filename);
	activeDocument.saveAs(tiffFile, tiffSaveOptions, true, Extension.LOWERCASE);   
	return tiffFile;
}

 

However, when I generate an array of filenames from the files I saved because I want to also stack those. That is where I run into problems, I get 

Error 21: undefined is not an object
Line: 56 (nothing on line 56)
-> this fName = decodeURI(f.name)

 

There is something wrong with the way Im using the filenames, and I cant get it to work. I populate an array of filenames like so

var nflist = new Array();	

tempfile = saveNewTiff(false); //save new tiff and return filename 
		
nflist.push(tempfile);

 

And I copy nflist back to my original file list.

			flist1.splice(0,flist1.length);
			for (j=0; j<nflist.length; j++){ //copy array item by item
				flist1[j] = new File(nflist[j]);
			}
			flist1 = nflist.getFiles();

Then once I try to use the new flist1 with making a stack, thats when I get the errors, I guess they are strings and not file objects or something?

Topics

Actions and scripting, Problem or error

Views

25

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Script stack loading issues with filenames

New Here ,
Aug 30, 2020

Copy link to clipboard

Copied

Hi, so I have a scrip to stack some files from a folder which works. 

 

var folder = new Folder('D:/RAW Compare/teststack');
var flist1 = folder.getFiles('*.tif');


cTID = function(s) { return cTID[s] || (cTID[s] = app.charIDToTypeID(s)); };
sTID = function(s) { return app.stringIDToTypeID(s); };

const deleteRecursives = true; //delete recursive stacked images once they are finished

function runLoadStack(fileList) {
    var loadLayersFromScript = true;
    // @include 'Load Files into Stack.jsx'
    //var fList = folder.getFiles('*.tif')
	var aFlag = true;
	
	loadLayers.intoStack(fileList, aFlag);
    loadLayers.alignStack = function( stackDoc ){
		selectAllLayers(stackDoc, 0);
	}

    
}

 

And I have another script to save a resulting tiff file which works. 

function saveNewTiff(fin){
	var doc = app.activeDocument;
	var fileName = File.decode(doc.name);
	var n = fileName.lastIndexOf(".");
	if (n > 0) fileName = fileName.substr(0, n);
	var d = new Date();
	if (fin==true){filename="FINAL_STACK_";}
	fileName += "_" + ("00" + d.getHours()).slice(-2) + "_" + ("00" + d.getMinutes()).slice(-2)+"_"+("00" + d.getSeconds()).slice(-2) + ".tif";
	fileName = folder + "/" + fileName
	//saveTiff(fileName)
	//alert(folder+fileName);
	return saveTiff(fileName);
}

function saveTiff(filename){
	tiffFile = new File(filename);
	tiffSaveOptions = new TiffSaveOptions();   
	tiffSaveOptions.embedColorProfile = true;   
	tiffSaveOptions.alphaChannels = true;   
	tiffSaveOptions.layers = true;  
	tiffSaveOptions.imageCompression = TIFFEncoding.NONE;  
	//alert(filename);
	activeDocument.saveAs(tiffFile, tiffSaveOptions, true, Extension.LOWERCASE);   
	return tiffFile;
}

 

However, when I generate an array of filenames from the files I saved because I want to also stack those. That is where I run into problems, I get 

Error 21: undefined is not an object
Line: 56 (nothing on line 56)
-> this fName = decodeURI(f.name)

 

There is something wrong with the way Im using the filenames, and I cant get it to work. I populate an array of filenames like so

var nflist = new Array();	

tempfile = saveNewTiff(false); //save new tiff and return filename 
		
nflist.push(tempfile);

 

And I copy nflist back to my original file list.

			flist1.splice(0,flist1.length);
			for (j=0; j<nflist.length; j++){ //copy array item by item
				flist1[j] = new File(nflist[j]);
			}
			flist1 = nflist.getFiles();

Then once I try to use the new flist1 with making a stack, thats when I get the errors, I guess they are strings and not file objects or something?

Topics

Actions and scripting, Problem or error

Views

26

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Aug 30, 2020

Copy link to clipboard

Copied

The issue turned out to be the script was expecting more files on the recursive loop when the stacknumber wasnt set to match the remaining number of files.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...