Because i can see several experts of ActionDescriptor() on this forum, i guess that my unanswered question is not very clear !
So i will try to do better (sorry for my english).
I am looking for a script function that can do a "perspective" transformation of a rectangle in a layer.
The following code is given by the scriptlistener for this action: In this example, only the bottom edge of the rectangle is resized at about 50%.
(I just add comments and remove duplicated definitions).
var idTrnf = charIDToTypeID( "Trnf" );
var idnull = charIDToTypeID( "null" );
var idHrzn = charIDToTypeID( "Hrzn" );
var idVrtc = charIDToTypeID( "Vrtc" );
var idRlt = charIDToTypeID( "#Rlt" );
var idPrc = charIDToTypeID( "#Prc" );
var desc3 = new ActionDescriptor();
var ref2 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref2.putEnumerated( idLyr, idOrdn, idTrgt );
desc3.putReference( idnull, ref2 );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc3.putEnumerated( idFTcs, idQCSt, idQcsa );
var desc4 = new ActionDescriptor();
desc4.putUnitDouble( idHrzn, idRlt, 0.000000 ); // Translate Horiz
desc4.putUnitDouble( idVrtc, idRlt, 17.171411 ); // Translate Verti
var idOfst = charIDToTypeID( "Ofst" );
desc3.putObject( idOfst, idOfst, desc4 );
var idWdth = charIDToTypeID( "Wdth" );
desc3.putUnitDouble( idWdth, idPrc, 73.076923 ); // Resize horiz (%)
var desc5 = new ActionDescriptor();
desc5.putUnitDouble( idHrzn, idPrc, -0.000000 ); // Rectangle->Trapezium Horiz
desc5.putUnitDouble( idVrtc, idPrc, 0.422127 ); // Rectangle->Trapezium Verti
var idPnt = charIDToTypeID( "Pnt " );
var idUsng = charIDToTypeID( "Usng" );
desc3.putObject( idUsng, idPnt, desc5 );
executeAction( idTrnf, desc3, DialogModes.NO );
One can see that the parameter values of this transformation are not very easy to understand.
The main part (that is the transformation rectangle->trapezium) is done at the end with only one value here : 0.422127.
The other values in that script are only used to correct the result, that needs to be resized at the same size (top edge) and translated at the same position.
The image below shows how this mysterious transformation (without resizing nor translating corrections) modifies a black rectangle.
Does somebody can explain what is the geometric calculation that produces such a result with a single value ?
This knowledge seems to be required to compute the correction factors.
Thanks for your answers.
Experience with scriptlistener does not help much with transform. The numbers used in the GUI to create the transform are often not the values used in the scriptlistner output. Photoshop seems to be making some conversions to the value entered in the GUI before making the transform.
In the past I have spent many hours trying to understand those conversions. As you said in your first post often what is entered in the GUI is converted to translate, scale, and/or rotate. I have given up trying to understand and have added those types of transforms with arguments to the list of things I can't do in a script.
If script needs to perform a specific distortion or perspective, you can record those to be used in the script. But I have not be able to make a distortion or perspective function that takes arguments.
Illustrator uses Matrix's for transformations and I've had a real tough time trying to get my head around those. Here is a link to (what I think is how you compute your value) Just don't ask me to try get my head around any of that… Sorry…
Thanks for your answers, even if it was negative.
I continued my searches and finally i found on the web a post with a good idea: use the warp transform to build other simplier transformations like distort and perspective (muller, ps-script.com 2007).
In fact the warp script (from scriptlistener) is far more understandable than other free transform scripts. It simply requires the new coordinates of the grid nodes, and not angles, factors or crypted values as other "rubix-cube like" basic transformations.
With simple calculations that modify the warp grid, it is possible to simulate any free transformation and more.
I finally built my perspective function starting from the scriptlistener script (but thanks to Muller for his idea). See the image below.
You should'nt give up Michael.