Continue script

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

MIRYAMM

Continue script

Post by MIRYAMM »

I have an action with a script,It must open a folder where I choose a texture, to open. The action stops, and I have to re-run the action to finish my photo.

I tried in every way possible, and always continuous action without opening the folder for choosing an texture.

All I need is that after you open the folder and choose the texture that I need for my photography, continue from step action where it left off.

I put the script that opens the folder

Code: Select allFolder("/C/Users/Public/Documents/Mary/texturas").execute();


Many thanks to all experts.

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Paul MR

Continue script

Post by Paul MR »

You need to get a list of files and let the user select the texture, as an example please see the attached...
MIRYAMM

Continue script

Post by MIRYAMM »

Thanks a million Paul.
It would be possible to modify the script a bit, so that:
default, open a specific folder in normal mode at 100% ?

Folder("/C/Users/Public/Documents/Mary/texturas").execute();

Paul MR

Continue script

Post by Paul MR »

This will let you select a texture file from your folder...

Code: Select all#target photoshop
function main(){
var win = new Window('dialog','Add Texture');
win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
win.g1 = win.p1.add('group');
win.g1.orientation = "row";
win.title = win.g1.add('statictext',undefined,'Add Texture');
win.title.alignment="fill";
var g = win.title.graphics;
g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);
win.g5 =win.p1.add('group');
win.g5.orientation = "row";
win.g5.alignment='fill';
win.g5.spacing=10;
win.g5.st1 = win.g5.add('statictext',undefined,'Texture');
var textureFolder = Folder("/C/Users/Public/Documents/Mary/texturas");
var fileList = textureFolder.getFiles(/\.(jpg|tif|psd)$/i);
win.g5.dd1 = win.g5.add('dropdownlist');
for(var a in fileList){
    var Name = decodeURI(fileList[a].name).replace(/\.[^\.]+$/, '');
    win.g5.dd1.add("item",Name);
    }
win.g5.dd1.selection=0;
win.g50 =win.p1.add('group');
win.g50.orientation = "row";
win.g50.alignment='fill';
win.g50.bu1 = win.g50.add('button',undefined,'Process');
win.g50.bu1.preferredSize=[100,35];
win.g50.bu2 = win.g50.add('button',undefined,'Cancel');
win.g50.bu2.preferredSize=[100,35];
win.g50.bu1.onClick=function(){
win.close(0);
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
doc.activeLayer = doc.layers[0];
placeFile(fileList[win.g5.dd1.selection.index]);
rasterLayer();
var LB = doc.activeLayer.bounds;
var docHeight = doc.height;
var docWidth = doc.width;
if(doc.height>doc.width){
var LHeight = Math.round(LB[3].value) - Math.round(LB[1].value);
var LWidth = Math.round(LB[2].value) - Math.round(LB[0].value);
if(LWidth> LHeight) activeDocument.activeLayer.rotate(90);
LB = doc.activeLayer.bounds;
    }
if(doc.height<doc.width){
var LHeight = Math.round(LB[3].value) - Math.round(LB[1].value);
var LWidth = Math.round(LB[2].value) - Math.round(LB[0].value);
if(LWidth<LHeight) activeDocument.activeLayer.rotate(90);
LB = doc.activeLayer.bounds;
}
LHeight = Math.round(LB[3].value) - Math.round(LB[1].value);
LWidth = Math.round(LB[2].value) - Math.round(LB[0].value);   
var perWidth = ((docWidth/LWidth)*100);
var perHeight = ((docHeight/LHeight)*100);
doc.activeLayer.resize(perWidth,perHeight,AnchorPosition.MIDDLECENTER);
LB = doc.activeLayer.bounds;
doc.activeLayer.translate((0-LB[0].value),(0-LB[1].value));
doc.activeLayer.opacity = 100;
doc.activeLayer.blendMode = BlendMode.NORMAL;
app.preferences.rulerUnits = startRulerUnits;
}   
win.show();
}
main();
function placeFile(file) {
var desc = new ActionDescriptor();
desc.putPath( charIDToTypeID('null'), new File( file ) );
desc.putEnumerated( charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa') );
var desc2 = new ActionDescriptor();
desc2.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), 0.000000 );
desc2.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), 0.000000 );
desc.putObject( charIDToTypeID('Ofst'), charIDToTypeID('Ofst'), desc2 );
desc.putBoolean( charIDToTypeID('AntA'), true );
executeAction( charIDToTypeID('Plc '), desc, DialogModes.NO );
};
function rasterLayer() {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc.putReference( charIDToTypeID('null'), ref );
executeAction( stringIDToTypeID('rasterizeLayer'), desc, DialogModes.NO );
};

MIRYAMM

Continue script

Post by MIRYAMM »

Thank you so much,
But only a bit.
When choosing the texture would need to open a window to view all (as does the previous script)
Very grateful for your patience
Paul MR

Continue script

Post by Paul MR »

Hope this is better for you...

Code: Select all#target photoshop
function main(){
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
doc.activeLayer = doc.layers[0];
var textureFile = File.openDialog("Please select Texture","*.*");
if (textureFile == null) return;
placeFile(textureFile);
rasterLayer();
var LB = doc.activeLayer.bounds;
var docHeight = doc.height;
var docWidth = doc.width;
if(doc.height>doc.width){
var LHeight = Math.round(LB[3].value) - Math.round(LB[1].value);
var LWidth = Math.round(LB[2].value) - Math.round(LB[0].value);
if(LWidth> LHeight) activeDocument.activeLayer.rotate(90);
LB = doc.activeLayer.bounds;
    }
if(doc.height<doc.width){
var LHeight = Math.round(LB[3].value) - Math.round(LB[1].value);
var LWidth = Math.round(LB[2].value) - Math.round(LB[0].value);
if(LWidth<LHeight) activeDocument.activeLayer.rotate(90);
LB = doc.activeLayer.bounds;
}
LHeight = Math.round(LB[3].value) - Math.round(LB[1].value);
LWidth = Math.round(LB[2].value) - Math.round(LB[0].value);   
var perWidth = ((docWidth/LWidth)*100);
var perHeight = ((docHeight/LHeight)*100);
doc.activeLayer.resize(perWidth,perHeight,AnchorPosition.MIDDLECENTER);
LB = doc.activeLayer.bounds;
doc.activeLayer.translate((0-LB[0].value),(0-LB[1].value));
doc.activeLayer.opacity = 100;
doc.activeLayer.blendMode = BlendMode.NORMAL;
app.preferences.rulerUnits = startRulerUnits;
}
main();
function placeFile(file) {
var desc = new ActionDescriptor();
desc.putPath( charIDToTypeID('null'), new File( file ) );
desc.putEnumerated( charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa') );
var desc2 = new ActionDescriptor();
desc2.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), 0.000000 );
desc2.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), 0.000000 );
desc.putObject( charIDToTypeID('Ofst'), charIDToTypeID('Ofst'), desc2 );
desc.putBoolean( charIDToTypeID('AntA'), true );
executeAction( charIDToTypeID('Plc '), desc, DialogModes.NO );
};
function rasterLayer() {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc.putReference( charIDToTypeID('null'), ref );
executeAction( stringIDToTypeID('rasterizeLayer'), desc, DialogModes.NO );
};
MIRYAMM

Continue script

Post by MIRYAMM »

Paul A thousand thanks for your time.

Please do not be angry with me, but I need to choose the folder.
What is happening is that the script opens the folder that is in memory
Paul MR

Continue script

Post by Paul MR »

Hop I have got it right this time

Code: Select all#target photoshop
function main(){
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
doc.activeLayer = doc.layers[0];
var textureFolder = Folder("/C/Users/Public/Documents/Mary/texturas");
var textureFile =textureFolder.openDlg("Please select Texture","*.*");
if (textureFile == null) return;
placeFile(textureFile);
rasterLayer();
var LB = doc.activeLayer.bounds;
var docHeight = doc.height;
var docWidth = doc.width;
if(doc.height>doc.width){
var LHeight = Math.round(LB[3].value) - Math.round(LB[1].value);
var LWidth = Math.round(LB[2].value) - Math.round(LB[0].value);
if(LWidth> LHeight) activeDocument.activeLayer.rotate(90);
LB = doc.activeLayer.bounds;
    }
if(doc.height<doc.width){
var LHeight = Math.round(LB[3].value) - Math.round(LB[1].value);
var LWidth = Math.round(LB[2].value) - Math.round(LB[0].value);
if(LWidth<LHeight) activeDocument.activeLayer.rotate(90);
LB = doc.activeLayer.bounds;
}
LHeight = Math.round(LB[3].value) - Math.round(LB[1].value);
LWidth = Math.round(LB[2].value) - Math.round(LB[0].value);   
var perWidth = ((docWidth/LWidth)*100);
var perHeight = ((docHeight/LHeight)*100);
doc.activeLayer.resize(perWidth,perHeight,AnchorPosition.MIDDLECENTER);
LB = doc.activeLayer.bounds;
doc.activeLayer.translate((0-LB[0].value),(0-LB[1].value));
doc.activeLayer.opacity = 100;
doc.activeLayer.blendMode = BlendMode.NORMAL;
app.preferences.rulerUnits = startRulerUnits;
}
main();
function placeFile(file) {
var desc = new ActionDescriptor();
desc.putPath( charIDToTypeID('null'), new File( file ) );
desc.putEnumerated( charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa') );
var desc2 = new ActionDescriptor();
desc2.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), 0.000000 );
desc2.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), 0.000000 );
desc.putObject( charIDToTypeID('Ofst'), charIDToTypeID('Ofst'), desc2 );
desc.putBoolean( charIDToTypeID('AntA'), true );
executeAction( charIDToTypeID('Plc '), desc, DialogModes.NO );
};
function rasterLayer() {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc.putReference( charIDToTypeID('null'), ref );
executeAction( stringIDToTypeID('rasterizeLayer'), desc, DialogModes.NO );
};
MIRYAMM

Continue script

Post by MIRYAMM »

Thanks, thanks, thanks,