Skip to main content
Inspiring
October 1, 2013
Answered

Returned Action Descriptor has no keys

  • October 1, 2013
  • 1 reply
  • 803 views

Hi everyone and thanks for your support,

I made a Action Descriptor for a perspective cropping tool (Using CS6). It receives the corner points and the middle point. When the action is executed, the user can change the corner points and crop the selection. The return value from executeAction is stored under a new Action Descriptor. Howeever, this Action Descriptor is empty and holds no keys. I would have expected it to hold the keys with the new corner point values.

Code is below.

app.preferences.rulerUnits = Units.PIXELS
var srcDoc = app.activeDocument;
var width = srcDoc.width;
var height = srcDoc.height;
var m1, m2, x1, x2, x3, x4, y1, y2, y3, y4;
var settings_dflt=[m1, m2, x1, y1, x2, y2, x3, y3, x4, y4];
settings_dflt = [width/2,height/2,0,0,width,0,width,height,0,height];
var actionDescriptor=new ActionDescriptor();
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

function defaultActionDesciptor(Fa){

var Ga=new ActionDescriptor();

var Ha=new ActionDescriptor();

var Ia=new ActionDescriptor();

Ia.putUnitDouble(cTID('Hrzn'),cTID('#Pxl'),Fa[0]);

Ia.putUnitDouble(cTID('Vrtc'),cTID('#Pxl'),Fa[1]);

Ha.putObject(cTID('Cntr'),cTID('Pnt '),Ia);

var Ja=new ActionDescriptor();

Ja.putUnitDouble(cTID('Hrzn'),cTID('#Pxl'),Fa[2]);

Ja.putUnitDouble(cTID('Vrtc'),cTID('#Pxl'),Fa[3]);

Ha.putObject(sTID('quadCorner0'),cTID('Ofst'),Ja);

var Ka=new ActionDescriptor();

Ka.putUnitDouble(cTID('Hrzn'),cTID('#Pxl'),Fa[4]);

Ka.putUnitDouble(cTID('Vrtc'),cTID('#Pxl'),Fa[5]);

Ha.putObject(sTID('quadCorner1'),cTID('Ofst'),Ka);

var La=new ActionDescriptor();

La.putUnitDouble(cTID('Hrzn'),cTID('#Pxl'),Fa[6]);

La.putUnitDouble(cTID('Vrtc'),cTID('#Pxl'),Fa[7]);

Ha.putObject(sTID('quadCorner2'),cTID('Ofst'),La);

var Ma=new ActionDescriptor();

Ma.putUnitDouble(cTID('Hrzn'),cTID('#Pxl'),Fa[8]);

Ma.putUnitDouble(cTID('Vrtc'),cTID('#Pxl'),Fa[9]);

Ha.putObject(sTID('quadCorner3'),cTID('Ofst'),Ma);

Ga.putObject(cTID('T   '),sTID('quadrilateral'),Ha);

Ga.putUnitDouble(cTID('Wdth'),cTID('#Pxl'),0.000000);

Ga.putUnitDouble(cTID('Hght'),cTID('#Pxl'),0.000000);

Ga.putUnitDouble(cTID('Rslt'),cTID('#Rsl'),0.000000);

return Ga;

    }

//

function CallAppropriateAction() {

  var fb = new ActionDescriptor(); 

  try{
     fb = executeAction(cTID('Crop'),actionDescriptor,DialogModes.ALL);
              }
         
         catch(e){
             alert("User cancelled operation");
             }
        
            if(fb!=null){
              
               srcDoc.selection.selectAll();
               alert(fb.count + " = number of keys in fb\n" + fb.typename + " = type of fb")
               }

}
//
function main()
{
   
    srcDoc.selection.selectAll();
    actionDescriptor=defaultActionDesciptor(settings_dflt);
    CallAppropriateAction();
       
}
//
app.activeDocument.suspendHistory("CropTool", "main()")

</code>


This topic has been closed for replies.
Correct answer BlackpainterAdi

Ok never mind, i found the embarassing mistake.

The problem was this:

var settings_dflt=[m1, m2, x1, y1, x2, y2, x3, y3, x4, y4];

settings_dflt = [width/2,height/2,0,0,width,0,width,height,0,height];

I kinda thought the variables in the array would be initialized with the values given to the array. However when i delete the second line and initialize the variables with the starting values before assigning them to the array, everything works fine.

var m1, m2, x1, x2, x3, x4, y1, y2, y3, y4;

m1 = width/2;

m2 = height/2;

x1 = 0;

y1 = 0;

x2 = width;

y2 = 0;

x3 = width;

y3 = height;

x4 = 0;

y4 = height;

var settings_dflt=[m1, m2, x1, y1, x2, y2, x3, y3, x4, y4];

1 reply

Inspiring
October 2, 2013

Ok, a small update.

I switched the

fb = executeAction(cTID('Crop'),actionDescriptor,DialogModes.ALL);

with

var idperspectiveCrop = stringIDToTypeID( "perspectiveCrop" );

fb = executeAction(idperspectiveCrop,actionDescriptor,DialogModes.ALL);

now at least the keys get returned. However, the values of the corners are the ones that are given to the actionDescriptor at the start instead of the new ones from the user. Any Help?

BlackpainterAdiAuthorCorrect answer
Inspiring
October 2, 2013

Ok never mind, i found the embarassing mistake.

The problem was this:

var settings_dflt=[m1, m2, x1, y1, x2, y2, x3, y3, x4, y4];

settings_dflt = [width/2,height/2,0,0,width,0,width,height,0,height];

I kinda thought the variables in the array would be initialized with the values given to the array. However when i delete the second line and initialize the variables with the starting values before assigning them to the array, everything works fine.

var m1, m2, x1, x2, x3, x4, y1, y2, y3, y4;

m1 = width/2;

m2 = height/2;

x1 = 0;

y1 = 0;

x2 = width;

y2 = 0;

x3 = width;

y3 = height;

x4 = 0;

y4 = height;

var settings_dflt=[m1, m2, x1, y1, x2, y2, x3, y3, x4, y4];