• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Capture last user performed action?

Explorer ,
May 29, 2019 May 29, 2019

Copy link to clipboard

Copied

Hello,

We are trying to capture data on how our users are cropping images.  We have a script that pops up a crop box, the user adjusts that crop box, hits enter, and it crops.  We would like to capture the TOP, BOTTOM, LEFT, RIGHT, and ANGLE that the user adjusted the crop box to before hitting enter.  I know that in ScriptListener it outputs these variables, but is there a way to capture these inside of the current script we are running? Here is the script we are running:

var docRef = app.activeDocument;

var r = docRef.width / 560;

var left = 0;

var right = docRef.width;

var top = (docRef.height - (336 * r)) / 2;

var bottom = (docRef.width + (336 * r)) / 2;

// ======================================================= CROP

var idCrop = charIDToTypeID( "Crop" );

    var desc146 = new ActionDescriptor();

    var idT = charIDToTypeID( "T   " );

        var desc147 = new ActionDescriptor();

        var idTop = charIDToTypeID( "Top " );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc147.putUnitDouble( idTop, idPxl, top );

        var idLeft = charIDToTypeID( "Left" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc147.putUnitDouble( idLeft, idPxl, left);

        var idBtom = charIDToTypeID( "Btom" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc147.putUnitDouble( idBtom, idPxl, bottom );

        var idRght = charIDToTypeID( "Rght" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc147.putUnitDouble( idRght, idPxl, right );

    var idRctn = charIDToTypeID( "Rctn" );

    desc146.putObject( idT, idRctn, desc147 );

    var idAngl = charIDToTypeID( "Angl" );

    var idAng = charIDToTypeID( "#Ang" );

    desc146.putUnitDouble( idAngl, idAng, 0.000000 );

    var idDlt = charIDToTypeID( "Dlt " );

    desc146.putBoolean( idDlt, true );

    var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" );

    var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" );

    var idtargetSize = stringIDToTypeID( "targetSize" );

    desc146.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idtargetSize );

    var idWdth = charIDToTypeID( "Wdth" );

    var idPxl = charIDToTypeID( "#Pxl" );

    desc146.putUnitDouble( idWdth, idPxl, 560.000000 );

    var idHght = charIDToTypeID( "Hght" );

    var idPxl = charIDToTypeID( "#Pxl" );

    desc146.putUnitDouble( idHght, idPxl, 336.000000 );

    var idRslt = charIDToTypeID( "Rslt" );

    var idRsl = charIDToTypeID( "#Rsl" );

    desc146.putUnitDouble( idRslt, idRsl, 300.000000 );

executeAction( idCrop, desc146, DialogModes.ALL );

// let user adjust crop box

// capture top, bottom, left, right, and angle that the user adjusted the crop box to

return cropBoxArguments

TOPICS
Actions and scripting

Views

894

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
community guidelines

correct answers 1 Correct answer

Guide , May 30, 2019 May 30, 2019

This will return the bounds, but the angle is not in the descriptor.

var docRef = app.activeDocument;

var r = docRef.width / 560;

var left = 0;

var right = docRef.width;

var top = (docRef.height - (336 * r)) / 2;

var bottom = (docRef.width + (336 * r)) / 2;

// ======================================================= CROP

alert(Crop(left,top,right,bottom));

function Crop(left,top,right,bottom) {

var ad = new ActionDescriptor();

var ad2 = new ActionDescriptor();

ad2.putUnitDouble( charIDToTypeID( "Top " ), cha

...

Votes

Translate

Translate
Adobe
Community Expert ,
May 29, 2019 May 29, 2019

Copy link to clipboard

Copied

A way  to do what you want to do is instead of putting the user into an interactive crop is to set an rectangle selection perhaps a select all then put the user into an interactive transform  selection to have them select the crop they want.  When they commit the transform the script can capture the selection  top left and bottom right bounds then do an Image Crop.

If you want the user to be able to do ad crop and straighten do that in two steps,  First have the straighten the omage. Capture the angle of Rotation used  then to the transform.

If you want to to is in as single Process perhaps you could set a rectangle Path the canvas size and put the user into an interactive transform path.  When the user commits the transform.  You cans get the four control points and figure the angle  rotation. Rotate the image and then crop the the path's selection.  The Problem there is the user could easily distort the rectangle path  the crop would still be rectangular. However,  the crops content would  not be only be the image content that was insude the transform Path.

The Problem I see with using your interactive Crop method is before the interactive crop you can get the canvas size and after the interactive crop you can get the canvas size.  However how would you know if there was any straightening rotation or what part of the original Image is the crop area.  With the transform selection method you can get the bounds of the selection to know what part of the image is the crop area.

The problem with any Interactive Transform  is the user can easily change the shape of the rectangular path or selection to a none rectangular shape.

Perhaps if you change the users preferences to record history  you could get some information from the history log about the crop that was performed.  I do not think you can get at data in the History palette states. I have never logged history so I do not  know what is recorded in History log metadata.

JJMack

Votes

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
community guidelines
Guide ,
May 30, 2019 May 30, 2019

Copy link to clipboard

Copied

This will return the bounds, but the angle is not in the descriptor.

var docRef = app.activeDocument;

var r = docRef.width / 560;

var left = 0;

var right = docRef.width;

var top = (docRef.height - (336 * r)) / 2;

var bottom = (docRef.width + (336 * r)) / 2;

// ======================================================= CROP

alert(Crop(left,top,right,bottom));

function Crop(left,top,right,bottom) {

var ad = new ActionDescriptor();

var ad2 = new ActionDescriptor();

ad2.putUnitDouble( charIDToTypeID( "Top " ), charIDToTypeID( "#Pxl" ), top );

ad2.putUnitDouble( charIDToTypeID( "Left" ), charIDToTypeID( "#Pxl" ), left);

ad2.putUnitDouble( charIDToTypeID( "Btom" ), charIDToTypeID( "#Pxl" ), bottom );

ad2.putUnitDouble( charIDToTypeID( "Rght" ), charIDToTypeID( "#Pxl" ), right );

ad.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "Rctn" ), ad2 );

ad.putUnitDouble( charIDToTypeID( "Angl" ), charIDToTypeID( "#Ang" ), 0.000000 );

ad.putBoolean( charIDToTypeID( "Dlt " ), true );

ad.putEnumerated( stringIDToTypeID( "cropAspectRatioModeKey" ), stringIDToTypeID( "cropAspectRatioModeClass" ), stringIDToTypeID( "targetSize" ));

ad.putUnitDouble( charIDToTypeID( "Wdth" ), charIDToTypeID( "#Pxl" ), 560.000000 );

ad.putUnitDouble( charIDToTypeID( "Hght" ), charIDToTypeID( "#Pxl" ), 336.000000 );

ad.putUnitDouble( charIDToTypeID( "Rslt" ), charIDToTypeID( "#Rsl" ), 300.000000 );

var desc = executeAction( charIDToTypeID( "Crop" ), ad, DialogModes.ALL );

var desc2 = desc.getObjectValue(stringIDToTypeID("to"))

var l=desc2.getDouble (charIDToTypeID( "Left" ) ).toFixed(0);

var t=desc2.getDouble (charIDToTypeID( "Top " ) ).toFixed(0);

var r=desc2.getDouble (charIDToTypeID( "Rght" ) ).toFixed(0);

var b=desc2.getDouble (charIDToTypeID( "Btom" ) ).toFixed(0);

return [l,t,r,b];

};

Votes

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
community guidelines
Community Beginner ,
May 30, 2019 May 30, 2019

Copy link to clipboard

Copied

Is there documentation somewhere on what values are available to extract from executeAction?

How did you know "Left", "Top ", "Rght", and "Btom" were available? Is there a way to see everything without extracting each one at a time?

Votes

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
community guidelines
Guide ,
May 30, 2019 May 30, 2019

Copy link to clipboard

Copied

Here is an example of seeing what is there...

var docRef = app.activeDocument;

var r = docRef.width / 560;

var left = 0;

var right = docRef.width;

var top = (docRef.height - (336 * r)) / 2;

var bottom = (docRef.width + (336 * r)) / 2;

// ======================================================= CROP

alert(Crop(left,top,right,bottom));

function Crop(left,top,right,bottom) {

var ad = new ActionDescriptor();

var ad2 = new ActionDescriptor();

ad2.putUnitDouble( charIDToTypeID( "Top " ), charIDToTypeID( "#Pxl" ), top );

ad2.putUnitDouble( charIDToTypeID( "Left" ), charIDToTypeID( "#Pxl" ), left);

ad2.putUnitDouble( charIDToTypeID( "Btom" ), charIDToTypeID( "#Pxl" ), bottom );

ad2.putUnitDouble( charIDToTypeID( "Rght" ), charIDToTypeID( "#Pxl" ), right );

ad.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "Rctn" ), ad2 );

ad.putUnitDouble( charIDToTypeID( "Angl" ), charIDToTypeID( "#Ang" ), 0.000000 );

ad.putBoolean( charIDToTypeID( "Dlt " ), true );

ad.putEnumerated( stringIDToTypeID( "cropAspectRatioModeKey" ), stringIDToTypeID( "cropAspectRatioModeClass" ), stringIDToTypeID( "targetSize" ));

ad.putUnitDouble( charIDToTypeID( "Wdth" ), charIDToTypeID( "#Pxl" ), 560.000000 );

ad.putUnitDouble( charIDToTypeID( "Hght" ), charIDToTypeID( "#Pxl" ), 336.000000 );

ad.putUnitDouble( charIDToTypeID( "Rslt" ), charIDToTypeID( "#Rsl" ), 300.000000 );

var desc = executeAction( charIDToTypeID( "Crop" ), ad, DialogModes.ALL );

var desc2 = desc.getObjectValue(stringIDToTypeID("to"))

var l=desc2.getDouble (charIDToTypeID( "Left" ) ).toFixed(0);

var t=desc2.getDouble (charIDToTypeID( "Top " ) ).toFixed(0);

var r=desc2.getDouble (charIDToTypeID( "Rght" ) ).toFixed(0);

var b=desc2.getDouble (charIDToTypeID( "Btom" ) ).toFixed(0);

actionDescriptor(desc);

actionDescriptor(desc2);

return [l,t,r,b];

};

function actionDescriptor(desc){

if(desc.typename == 'ActionDescriptor'){

    var c = desc.count;

    for(var i=0;i<c;i++){ //enumerate descriptor's keys

      $.writeln('AD '+zeroPad( i+1, 2 )+' = '+IDTz(desc.getKey(i)) +' : '+desc.getType(desc.getKey(i)));

    }

}

function IDTz(id){

     try {

          var res = typeIDToStringID( id );

          if(res == '' ){

               var res = typeIDToCharID( id );

          }

     }catch(e){}

     return res;

}

function zTID( s ){

     if( s.length == 4 ) var res = charIDToTypeID( s );

     if( s.length > 4 ) var res = stringIDToTypeID( s );

     return res;

}

function zeroPad(num,pad) {

     var z = Math.pow(10,Number(pad))

     return num <= z ? ((Number( num) + z).toString().substr(1)): num

}

};

Votes

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
community guidelines
LEGEND ,
Nov 10, 2021 Nov 10, 2021

Copy link to clipboard

Copied

Your code has been edited. Next time use </> for scripts, to avoid shrinked 'spaces': "T "

Votes

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
community guidelines
LEGEND ,
Nov 10, 2021 Nov 10, 2021

Copy link to clipboard

Copied

I meant to use code blocks while posting scripts.

Votes

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
community guidelines
LEGEND ,
Nov 12, 2021 Nov 12, 2021

Copy link to clipboard

Copied

Votes

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
community guidelines
LEGEND ,
Nov 13, 2021 Nov 13, 2021

Copy link to clipboard

Copied

Just make a crop, then copy the result from log of ScriptListener and change ALL to NO.

Votes

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
community guidelines
LEGEND ,
Nov 13, 2021 Nov 13, 2021

Copy link to clipboard

Copied

LATEST

I just did what I said and it works. Additionally by deafult it writes NO to SL, so for me is OK.

Votes

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
community guidelines