Hi everyone,
I am new here and to PS Scripting. I was not too bad at programming before the advent of Object Languages, so I am trying to automate some of the tasks I do regularly.
The following script worked perfectly in CS5 but in CS6 does not see the "resizeTarget" so it keeps resizing the image in 110% increments indefinitely.
Since I only have "ExtendScript Toolkit" for a debugger and I am not very good with it, I can't follow the variables changes.
Could someone help me please debug this or suggest a way to follow the evolution of the variables in a step by step debugging situation.
Any comments are welcomed and appreciated.
Code: Select all///////////////////////////////////////////////////////////////////////////////////////////////////////////
//Program to resize an image to a particular dimension //
//in 110% steps with resampling mode = bicubicSmoother //
//by Pierre Doré //
//////////////////////////////////////////////////////////////////////////////////////////////////////////
#target photoshop
var docWidth = 0;
var docHeight = 0;
var largerDim = 0;
var resolution = app.activeDocument.resolution;
var resizeTarget = 3872; // Change to required dimension
var stepSize = 110; // Resize steps
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
getLargeDim();
// Loop the required number of times at 110% then resize to target
while (largerDim < resizeTarget ) {
getLargeDim();
if(largerDim * 1.1 > resizeTarget) {
stepSize =resizeTarget/largerDim*100;
}
step1();
}
step2();
// Get larger dimension
function getLargeDim() {
docWidth = app.activeDocument.width;
docHeight = app.activeDocument.height;
if (docWidth >= docHeight) {
largerDim = docWidth;
}
else {
largerDim = docHeight;
}
// return largerDim;
}
// Resize with stepSize
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putUnitDouble(cTID('Wdth'), cTID('#Prc'), stepSize);
desc1.putBoolean(sTID("scaleStyles"), true);
desc1.putBoolean(cTID('CnsP'), true);
desc1.putEnumerated(cTID('Intr'), cTID('Intp'), sTID("bicubicSmoother"));
executeAction(sTID('imageSize'), desc1, dialogMode);
}
// Fit to screen
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Mn '), cTID('MnIt'), cTID('FtOn'));
desc1.putReference(cTID('null'), ref1);
executeAction(cTID('slct'), desc1, dialogMode);
};
Many thanks,
Pierre
It worked in CS5
-
Paul MR
It worked in CS5
Sometimes it is just easier to write the script from scratch.
Code: Select all#target photoshop
main();
function main(){
if(!documents.length) return;
//make sure you are working with pixels
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
var docWidth = doc.width.value;
var docHeight = doc.height.value;
var resizeTarget = 3872; // Change to required dimension
var Max = Math.max(docWidth,docHeight);
if(Max > resizeTarget) return;
var Step = (resizeTarget - Max)/10;
if(docWidth>docHeight){
for(var a = 0;a<9;a++){
doc.resizeImage((doc.width.value + Step), undefined, undefined, ResampleMethod.BICUBICSMOOTHER);
}
doc.resizeImage(resizeTarget, undefined, undefined, ResampleMethod.BICUBICSMOOTHER);
}else{
for(var a = 0;a<9;a++){
doc.resizeImage(undefined,(doc.height.value + Step), undefined, ResampleMethod.BICUBICSMOOTHER);
}
doc.resizeImage(undefined,resizeTarget, undefined, ResampleMethod.BICUBICSMOOTHER);
}
app.preferences.rulerUnits = startRulerUnits;
runMenuItem(app.charIDToTypeID("FtOn"));
}
Code: Select all#target photoshop
main();
function main(){
if(!documents.length) return;
//make sure you are working with pixels
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
var docWidth = doc.width.value;
var docHeight = doc.height.value;
var resizeTarget = 3872; // Change to required dimension
var Max = Math.max(docWidth,docHeight);
if(Max > resizeTarget) return;
var Step = (resizeTarget - Max)/10;
if(docWidth>docHeight){
for(var a = 0;a<9;a++){
doc.resizeImage((doc.width.value + Step), undefined, undefined, ResampleMethod.BICUBICSMOOTHER);
}
doc.resizeImage(resizeTarget, undefined, undefined, ResampleMethod.BICUBICSMOOTHER);
}else{
for(var a = 0;a<9;a++){
doc.resizeImage(undefined,(doc.height.value + Step), undefined, ResampleMethod.BICUBICSMOOTHER);
}
doc.resizeImage(undefined,resizeTarget, undefined, ResampleMethod.BICUBICSMOOTHER);
}
app.preferences.rulerUnits = startRulerUnits;
runMenuItem(app.charIDToTypeID("FtOn"));
}
-
pdophoto
It worked in CS5
Hi Paul,
Thanks for the prompt respond.
Your programming is way better then mine, the program looks very good indeed.
I will try it and see how it works and try to write another version of the one I use to size down to 1024.
So thanks again
Pierre
Thanks for the prompt respond.
Your programming is way better then mine, the program looks very good indeed.
I will try it and see how it works and try to write another version of the one I use to size down to 1024.
So thanks again
Pierre
-
pdophoto
It worked in CS5
To Paul MR,
thank you very much, both scripts work perfectly.
Is there a debugger that shows the variable states while running a script step by step?
Pierre
thank you very much, both scripts work perfectly.
Is there a debugger that shows the variable states while running a script step by step?
Pierre
-
Paul MR
It worked in CS5
Yes, you can use ExtendScript Toolkit, this gets installed with Photoshop.
It is the Integrated Development Environment (IDE) supplied to write/run scripts to the installed Adobe applications.
You can step through each line using F11 and look at the data browser window.
Hope it helps.
It is the Integrated Development Environment (IDE) supplied to write/run scripts to the installed Adobe applications.
You can step through each line using F11 and look at the data browser window.
Hope it helps.
-
pdophoto
It worked in CS5
Thanks, I will have a look with F11. Last time I tried stepping with the icon it didn't show any results.
Pierre
Pierre
-
Mike Hale
It worked in CS5
F11 is the same as the icon( except you can keep the mouse where it was ). Unless the current line is in a function it's in the global namespace. Your variable should be somewhere in that long list.
-
pdophoto
It worked in CS5
Thanks Mike.
I tried it and found the place where to look.
I am learning so many things these days that I should already know.
So thanks again.
Pierre
I tried it and found the place where to look.
I am learning so many things these days that I should already know.
So thanks again.
Pierre