Select Crop tool and Tool preset but do nothing

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

txuku

Select Crop tool and Tool preset but do nothing

Post by txuku »

I do not know how ...............

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

pfaffenbichler

Select Crop tool and Tool preset but do nothing

Post by pfaffenbichler »

Does the code in that thread help?
http://forums.adobe.com/thread/883250?tstart=0

One could calculate the values for another bounds-Array, I guess.
Mcquiff

Select Crop tool and Tool preset but do nothing

Post by Mcquiff »

Thats the right idea,

I've tried joining it to the code as posted before. but I can't get it to use the crop tool, as it would mean that it would have the correct ratio and locked when resizing. This is what i'm hoping for when the script has ended

Many Thanks

Matt


here is the code from the link


Code: Select allif(outsideInput){
     app.displayDialogs = DialogModes.ALL;
     app.activeDocument.crop(cropArea);
     app.displayDialogs = DialogModes.NO;
}else{app.activeDocument.crop(cropArea)}   
Paul MR

Select Crop tool and Tool preset but do nothing

Post by Paul MR »

Here is an example using the crop tool, not a preset...

Code: Select allvar strtRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var W = activeDocument.width;
var H = activeDocument.height;
//amend to suit
var ratio = "3:2";
var Res = 0;
ratio = ratio.split(":");
if(W<H) ratio=ratio.reverse();
var Hpics =(W/Number(ratio[0]))*Number(ratio[1]);
if(Hpics > H){
    Wpics = (H/Number(ratio[1]))*Number(ratio[0]);
    Hpics = H;
    }else{
        Wpics = W;
        }
var Left,Top,Right,Bottom=0;
if (W==Wpics) Left = 0; Right = W;
if (W!=Wpics) {
    var diffw = (W-Wpics)/2;
    Left = diffw; Right = Wpics+diffw;
    }
if (H==Hpics) Top = 0; Bottom = H;
if( H!=Hpics){
    var diffh = (H-Hpics)/2;
    Top = diffh; Bottom = Hpics+diffh;
    }
CropToRatio(Left,Top,Right,Bottom,Res);
app.preferences.rulerUnits = strtRulerUnits;
function CropToRatio(Left,Top,Right,Bottom,Res) {
if(Res == undefined) Res = 0;
var Width = Right-Left;
var Height = Bottom - Top;
    var desc = new ActionDescriptor();
        var desc2 = new ActionDescriptor();
        desc2.putUnitDouble( charIDToTypeID('Left'), charIDToTypeID('#Pxl'), Number(Left) );
        desc2.putUnitDouble( charIDToTypeID('Top '), charIDToTypeID('#Pxl'), Number(Top ));     
        desc2.putUnitDouble( charIDToTypeID('Rght'), charIDToTypeID('#Pxl'), Number(Right));
        desc2.putUnitDouble( charIDToTypeID('Btom'), charIDToTypeID('#Pxl'), Number(Bottom) );
    desc.putObject( charIDToTypeID('T   '), charIDToTypeID('Rctn'), desc2 );
    desc.putUnitDouble( charIDToTypeID('Angl'), charIDToTypeID('#Ang'), 0.000000 );
    desc.putBoolean( charIDToTypeID('Dlt '), true );
   desc.putUnitDouble( charIDToTypeID('Rslt'), charIDToTypeID('#Rsl'), Number(Res) );
    desc.putEnumerated( stringIDToTypeID('cropAspectRatioModeKey'), stringIDToTypeID('cropAspectRatioModeClass'), stringIDToTypeID('pureAspectRatio') );
  desc.putUnitDouble( charIDToTypeID('Wdth'), charIDToTypeID('#Pxl'),Number(Width));
    desc.putUnitDouble( charIDToTypeID('Hght'), charIDToTypeID('#Pxl'), Number(Height) );
    try{
    executeAction( charIDToTypeID('Crop'), desc, DialogModes.ALL );
    }catch(e){}
};
Mcquiff

Select Crop tool and Tool preset but do nothing

Post by Mcquiff »

Just trying to work out how to remove the if cmd?

In that even if the image is in the Landscape, then the crop should come on the screen filling top to bottom. Hope that makes sense?

Otherwise having tested it it works as I hoped it would!

Many Thanks