Photoshop Javascript

From bernie's
Jump to: navigation, search

Modelling

Old poly tool: SplitPolygonTool;

all alyers transform

no easy way to get the selection





docs = app.documents;
ad= app.activeDocument;

for(i = 0;i<ad.layers.length;i++){ 
    ad.layers[i].rotate(Math.random()-.5);
    r = (Math.random()*2-1);
    ad.layers[i].resize(99+r,99+r);
}


All documents to current document

9mtpo.png

docs = app.documents;
ad= app.activeDocument;
for(i = 0;i<docs.length;i++){
    if(docs[i]!=ad){
        activeDocument = docs[i];
        docs[i].selectAll;
        docs[i].layers[0].copy(); 
        activeDocument = ad;
        ad.paste();
     }
}
while(docs.length>1){
    //hackish but works
    for(i = 0;i<docs.length;i++){
        if(docs[i]!=ad){
            docs[i].close(SaveOptions.DONOTSAVECHANGES); 
        }
    }
}

Incremental Save

// incrementalsave
//
// checks if there is a double underscore in filename, if not adds them starting at 0001 
// else increments and saves as 24bit png (filename__####.png) in the doc's folder
// 
//
// feel free to use & modify - mbernadat@gmail.com
//
//
// only tested on vista+cs3

function remEx(f) {
	extPeriod = f.lastIndexOf(".");
	if(extPeriod > 0){
		return f.substr(0,extPeriod);
	}else{
		return false;
	}
}
function getIncrPos(nameWithoutExt){
	pos = nameWithoutExt.lastIndexOf("__");
	return nameWithoutExt.substr(pos+2,nameWithoutExt.length);
}
function basenameKindOf(path,match) {
	a = path.lastIndexOf(match);
	if(a > 0){;
		return path.substr(a,path.length);
	}else{
		return false;
	}
}
function addZeros(number){
	if(number<10){
		number = "000"+number;	
	}else if(number<100){
		number = "00"+number;
	}else if(number<1000){
		number = "0"+number;
	}
	return number;
}



docP = app.activeDocument.path;
docN = remEx(app.activeDocument.name);

docFold = new Folder (app.activeDocument.path);
files = docFold.getFiles(docN+"__*.png");
files =	Folder.decode(files);

if(files.length == 0){
	numbering = 0;
}else{
	files = files.split(",");
	numbering = 0;
	for(var i in files){
		curNumb = getIncrPos(remEx(basenameKindOf(files[i],docN)));
		numbering = Math.max(numbering,curNumb);
		//alert("'"+remEx(files[i])+"'");
	}
}
numbering++;
numbering = addZeros(numbering);

var exportOptions = new PNGSaveOptions();
//var type = ExportType.PNG24;
var fileSpec = new File(docP+"/"+docN+"__"+numbering+".png");
exportOptions.antiAliasing = true;
exportOptions.transparency = true;
exportOptions.saveAsHTML = false;
app.activeDocument.saveAs(fileSpec,exportOptions,1,Extension.LOWERCASE);