Hi guys,
Thank you for your feedback!
Probably I wasn’t clear enough about what I’m trying to do.
Here’s the script I’m writing.


The main idea is to find frames of a certain object style using a number of “conditions” and apply a number of transformations to them.
A condition may be either an exact value or a range of numbers; it can also be positive or negative – is/is not.
For example, in the screenshots above, I want to find frames with “My style” applied whose X position is 0 and Y is not 10-20 and scale them down by 50% both horizontally and vertically using the top-left anchor point.
Now let’s see how I implemented this in code:
function TransformFrame(frame) {
var transMatrix = null;
try {
if (set.cb_widthSet) {
// Not implemented yet
}
if (set.cb_heightSet) {
// Not implemented yet
}
if (set.cb_xSet) { // This doesn't work properly
transMatrix = CatenateMatrix(transMatrix, "horizontalTranslation", set.xSet);
}
if (set.cb_ySet) { // This doesn't work properly
transMatrix = CatenateMatrix(transMatrix, "verticalTranslation", set.ySet);
}
// The following part works as expected
if (set.cb_xScaleSet) {
transMatrix = CatenateMatrix(transMatrix, "horizontalScaleFactor", set.xScaleSet / 100);
}
if (set.cb_yScaleSet) {
transMatrix = CatenateMatrix(transMatrix, "verticalScaleFactor", set.yScaleSet / 100);
}
if (set.cb_rotationSet) {
transMatrix = CatenateMatrix(transMatrix, "counterclockwiseRotationAngle", set.rotationSet);
}
if (set.cb_skewSet) {
transMatrix = CatenateMatrix(transMatrix, "clockwiseShearAngle", set.skewSet);
}
frame.transform(CoordinateSpaces.PASTEBOARD_COORDINATES, anchorPoint, transMatrix);
}
catch(err) {
$.writeln(err.message + ", line: " + err.line);
}
}
function CatenateMatrix(transMatrix, property, value) {
if (transMatrix == null) {
transMatrix = eval("app.transformationMatrices.add({" + property + ":" + value + "});");
}
else {
transMatrix = transMatrix.catenateMatrix(eval("app.transformationMatrices.add({" + property + ":" + value + "});"));
}
return transMatrix;
}
If a check box is on, a new matrix is created for the parameter and is sent to the CatenateMatrix function which either creates a new matrix, if it doesn't exist yet, or catenates it with already existing one. At the end of the TransformFrame function all the transformations are applied in one go.
Here in the code the Set object gets parameters from the dialog box.
set.cb_xSet -- the 'set X' check box is on/off
set.cb_ySet -- the 'set Y' check box is on/off
set.xSet -- the X coordinate where to move the object (only if the 'set X to' check box is on)
set.ySet -- the Y coordinate where to move the object (only if the 'set Y to' check box is on)
and so on.
With horizontalTranslation and verticalTranslation the 2nd 'from' parameter doesn't work: the top-left point is always used. Note: this is a required parameter! And I didn't see that this parameter isn't applicable for hor/ver translation in the reference so I think it's a bug.
In UI if you select a frame and set X, say, to 50pt first using the top-left point and then using the bottom-right point, you'll get totally different results:


So the script should work in the same way.
Now I see that I have to write a function for moving X, Y and setting Width, Height on my own to handle all the possible 9 anchor points.
Kasyan, in case this is unclear: 1. If you want to change the proxy points in the UI for any reason, do it with the property transformReferencePoint of the layoutWindow. 2. The values for horizontal and vertical transformation in a transformation matrix are always expressed as points. Regradless of the measurement systems set for the rulers. |
1. I tried this, but it changes the proxy point on the screen only, but transformation is made using top-left point as before (move, transform methods)
2. The script works in points only because my client doesn't use other units.
Regards,
Kasyan
There would be a lot to say here but I lack time to explain in depth, so just keep in mind that the from parameter of the transform method is nothing but a temporary location which provides the origin of the transformation to be applied. This origin plays an important role in SCALING and ROTATION effects but it has no impact on the TRANSLATION component.
It would be wrong to think that the TRANSLATION components reflect the location of the object in the ruler space. When you need to reach a certain location through a translation, you always have to calculate the [tx,ty] parameters as offsets. This is what is done here Move object by "Reference Point" (as mentioned by tpk1982.)