Skip to main content
kwyjibo
Participant
March 21, 2014
Question

Get user settings from a Canvas Resize dialog using executeAction

  • March 21, 2014
  • 1 reply
  • 536 views

Hi,

I'm trying to get the user settings from the canvas resize dialog. I want to ask once, and the use those settings, mainly the anchor point, in the rest of images. This is what I have:

var inputDesc = new ActionDescriptor();

var idWdth = charIDToTypeID( "Wdth" );

var idPxl = charIDToTypeID( "#Pxl" );

inputDesc.putUnitDouble( idWdth, idPxl, tImageWidth );

var idHght = charIDToTypeID( "Hght" );

var idPxl = charIDToTypeID( "#Pxl" );

inputDesc.putUnitDouble( idHght, idPxl, tImageHeight );

var outputDesc = executeAction( charIDToTypeID( "CnvS" ), inputDesc, DialogModes.ALL );

var idHrzV = outputDesc.getEnumerationValue( charIDToTypeID( "Hrzn" ) );

var idVrtV = outputDesc.getEnumerationValue( charIDToTypeID( "VrtC" ) );

With the values on idHrzV and idVrtV, I'll call resizeCanvas, but it seems executeAction is not returning nothing. Did I get it wrong? Maybe this is not possible at all... If you have any suggestions, please, let me know.

This topic has been closed for replies.

1 reply

Tom Ruark
Inspiring
March 21, 2014

You probably want to inspect your outputDesc a bit further. I have a DescriptorToObject routine that I use. It shows me this as the output of Canvas Size.

Result: ({relative:true, width:{type:"#Pxl", typeString:"pixelsUnit", value:-647}, height:{type:"#Pxl", typeString:"pixelsUnit", value:-748}, horizontal:{type:"HrzL", typeString:"horizontalLocation", value:"Rght", valueString:"right"}, vertical:{type:"VrtL", typeString:"verticalLocation", value:"Bttm", valueString:"bottomEnum"}})

See the routine in the attached script.

And you might not get anything out if user just presses ok.

But I think you want this:

var idHrzV = outputDesc.getEnumerationValue( stringIDToTypeID( "horizontal" ) );

var idVrtV = outputDesc.getEnumerationValue( stringIDToTypeID( "vertical" ) );

kwyjibo
kwyjiboAuthor
Participant
March 24, 2014

Thanks Tom!

I thought that the returned ActionDescriptor would have the same structure as the input one, now I can get the values selected by the user:

idHrzV = typeIDToCharID( outputDesc.getEnumerationValue( stringIDToTypeID( "horizontal" ) ) );

idVrtV = typeIDToCharID( outputDesc.getEnumerationValue( stringIDToTypeID( "vertical" ) ) );

But I found another problem, a weird behaviour, the script I am doing, from an input picture, ouputs the same picture with a list of predefined aspect ratios, both expanding the canvas to fit the aspect ratio, or by cropping it. So I ask the user for the anchor poing twice per image. The weird thing is, the first time I ask, the ActionDescriptor only have the width and horizontal anchor:

objectName : (new String("Photoshop Application"))

width : ({type:"#Pxl", typeString:"pixelsUnit", value:4196})

horizontal : ({type:"HrzL", typeString:"horizontalLocation", value:"Left", valueString:"left"})

And the next time it return only the height and the vertical anchor:

objectName : (new String("Photoshop Application"))

height : ({type:"#Pxl", typeString:"pixelsUnit", value:7460})

vertical : ({type:"VrtL", typeString:"verticalLocation", value:"Bttm", valueString:"bottomEnum"})

I'm using Photoshop CS6 (64bit), what can be the problem? :/

kwyjibo
kwyjiboAuthor
Participant
March 24, 2014

Just a minor update, tested in the 32 bit version, it worked the first or second time, but then it started to do it again. I tried closing Photoshop and open it again, but same thing. I'll check if restarting the computer makes any difference, but for now, I created my own dialog

Any case, I'm just curious about why this is not working properly, I'm sure it's just a small detail...