Copy link to clipboard
Copied
Trying to come up with a script that moves a selected page item (text frame, graphic frame, etc), or many page items (eventually), 1 pica to the right (to start, will eventually have many scripts attached to keyboard shortcut for every direction)?
The below script is what I have so far. You would think it would be straight forward, but with everything I’ve read I’m left scratching my head on this one.
Any help is very much appreciated. Cheers.
var myPageItem = app.activeDocument.selection[0];
myPageItem.TransformationMatrix.translateMatrix.properties = {
horizontalTranslation:("1p"),
verticalTranslation:(0),
};
Hi Neal,
why not using method move() ?
move() for a selected page item has two arguments:
to and by
You'd need the second one, the by argument.
The trick here is to declare the first one as undefined.
app.selection[0].move( undefined , [ "1p" , 0 ] );
Regards,
Uwe
Copy link to clipboard
Copied
Hi Neal,
why not using method move() ?
move() for a selected page item has two arguments:
to and by
You'd need the second one, the by argument.
The trick here is to declare the first one as undefined.
app.selection[0].move( undefined , [ "1p" , 0 ] );
Regards,
Uwe
Copy link to clipboard
Copied
Nice. I started out using move, but didn’t understand the “to” and “by” parameters [?] array format.
This is great, now I have these moves at my finger tips and no longer need to rely on the Transform > Move command.
I regularly have situations where I jump specifically by either a pica or by 9 pt increments (screenshot below).
This is awesome.
Thanks again.
Copy link to clipboard
Copied
..also is there a way to select more than one and move them all at the same time...?
I know it involves a variable (n, i, etc) and <> symbols and ++, etc...and the .length method [?]...?
The instances of loops [?] that I’ve seen in my preexisting scripts leave me lost as to how to implement a loop in this, in what I’m assuming should be, simple code.
Thanks again, you’ve saved me a thousand times over and I really do appreciate it. Cheers.
Copy link to clipboard
Copied
Hi Neal,
you'd loop through the selection:
var sel = app.selection;
for(var n=0;n<sel.length;n++)
{
sel
.move(undefined , ["1p0",0] ); };
Regards,
Uwe
Copy link to clipboard
Copied
..also I see var (variable, right?) blatantly written out, yet I also see instances where variables are defined (i.e. sel = app.selection, etc) without the blatant syntax var invoked? Is there are reason for that, or is it simply preference, i.e. clean script versus sloppy scripting?
Thanks again.
Copy link to clipboard
Copied
Hi Neal,
var is for variable declaration.
Don't go without it unless you know what you're doing.
( Sorry for my brief statement. )
Read about variable declaration with var and without var, also about the scope of variables with JavaScript. Can a function see a variable? Can a different script see a variable that is declared by another script? Best search the forum here for e.g. "target engine". But also know, that ExtendScript is based on the old 3rd Edition of the ECMA-262 Standard plus an API for file handling and not on the modern version of JavaScript that is used e.g. for CEP HTML panels if you are looking for resources and documentation on the web…
Regards,
Uwe
Copy link to clipboard
Copied
Hi,
here is the version with the transformation matrix:
var curSel = app.selection[0];
var myTransformationMatrix = app.transformationMatrices.add();
// translateMatrix takes two parameters: horizontallyBy and verticallyBy
myTransformationMatrix = myTransformationMatrix.translateMatrix(72, 0);
curSel.transform(CoordinateSpaces.pasteboardCoordinates, AnchorPoint.centerAnchor, myTransformationMatrix);
You need to convert from pica to points I believe.
Thanks Stefan
Copy link to clipboard
Copied
https://forums.adobe.com/people/Stefan+Rakete wrote
… You need to convert from pica to points I believe.Thanks Stefan
Hi Stefan,
absolutely.
The problem may be that you cannot use UnitValue for this.
And how many Points go into one Pica? ( 12 )
How to deal with expressions like "1p7" ?
I'm not at all familiar with using Picas, but this should work:
var xAsPicas = "1p7";
var xInPoints = Number( xAsPicas.split("p")[0] )*12 + Number( xAsPicas.split("p")[1] );
Regards,
Uwe