Copy link to clipboard
Copied
Hi all!
Would there be a way to find text frames with the same x and y coordinates
in a document and make a change to the x and y coordinates that would change
all the text frames by a script of some sort?
Thanks a bunch for your help!
Austin Witmer_2
Copy link to clipboard
Copied
Yes there is a way to do this. 😃
Copy link to clipboard
Copied
… Something like this:
var myTF = app.activeDocument.textFrames.everyItem().getElements();
var x = 10;
var y = 15;
var movex = 8;
var movey = 22;
for ( i = 0; i < myTF.length; i++)
{
var gB = myTF.geometricBounds;
var y1 = gB[0].toFixed(2);
var x1 = gB[1].toFixed(2);
if (y1 == y && x1 == x) myTF.geometricBounds = [gB[0]+movey, gB[1]+movex, gB[2]+movey, gB[3]+movex];
}
[ need to be confirmed by the experts! ]
(^/)
Copy link to clipboard
Copied
Still not a great master of UI!
Done!
[ To be validated by the [JS] Masters! ]
var myDoc = app.activeDocument;
var w = new Window ('dialog {alignChildren: "top"}', 'Move TF (x,y) To (newx, newy)!');
w.alignChildren = "right";
var group1 = w.add ('group');
group1.add ('statictext {text: "Type the old x:"}');
var UIx = group1.add ("edittext", undefined, 0);
UIx.characters = 5;
UIx.minimumSize.width = 60;
UIx.maximumSize.width = 60;
UIx.active = true;
var group2 = w.add ('group');
group2.add ('statictext {text: "… and the old y:"}');
var UIy = group2.add ("edittext", undefined, 0);
UIy.characters = 5;
UIy.minimumSize.width = 60;
UIy.maximumSize.width = 60;
var group3 = w.add ('group');
group3.add ('statictext {text: "Type the new x:"}');
var UInewx = group3.add ("edittext", undefined, 0);
UInewx.characters = 5;
UInewx.minimumSize.width = 60;
UInewx.maximumSize.width = 60;
var group4 = w.add ('group');
group4.add ('statictext {text: "… and the new y:"}');
var UInewy = group4.add ("edittext", undefined, 0);
UInewy.characters = 5;
UInewy.minimumSize.width = 60;
UInewy.maximumSize.width = 60;
var buttons = w.add ('group {alignment: "center"}');
buttons.add ('button {text: "OK"}');
buttons.add ('button {text: "Cancel"}');
if (w.show () == 1) {
var x = Number (UIx.text);
x = x.toFixed(2);
var y = Number (UIy.text);
y = y.toFixed(2);
var newx = UInewx.text;
var newy = UInewy.text;
}
else
exit ();
app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Move TF (x,y) To (newx, newy)!");
function main()
{
var myTF = myDoc.textFrames.everyItem().getElements();
for ( i = 0; i < myTF.length; i++)
{
var gB = myTF.geometricBounds;
var y1 = gB[0].toFixed(2);
var x1 = gB[1].toFixed(2);
if ( y1 == y && x1 == x ) myTF.move([newx, newy]);
}
}
(^/)
Copy link to clipboard
Copied
This was extremely helpful!
Thank you very much! I can’t figure out a way to mark your answer as correct, otherwise I would.
Copy link to clipboard
Copied
You're welcome! It was funny (and interesting) to write and I would be truly interested by [JS] Masters' comments!
(^/)
Copy link to clipboard
Copied
Now I've got another question. Would there be a way to modify this script so that it would work for graphic frames and not just text frames?
Thanks in advance!
Copy link to clipboard
Copied
I guess Equalizer might be of some help here…
http://www.indiscripts.com/blog/public/scripts/en_Equalizer-Manual.pdf
Best,
Marc
Copy link to clipboard
Copied
See the line where Obi-Wan uses "myDoc.textFrames.everyItem()"? That is to specifically target just these (which is what you asked for).
Documents have a general 'pageItems' property, which enumerates all items in the document, so not just text frames and graphics, but lines and rectangles and polygons and ovals and groups as well. ("Groups" make life interesting here. If I recall correctly, it and its contents are reported twice.)
To target just graphic containers, you'd typically use 'myDoc.allGraphics' (without the 'everyItem().getElements() part', it's not a set of objects but already a plain array). Then, for each graphic – the image inside any kind of frame – you use its parent's geometricBounds – the frame in which the graphic is placed.
Copy link to clipboard
Copied
Thanks all for your help!
A friend of mine suggested that I change textFrames to pageItems instead and that has worked perfectly for me!
Cheers!
Copy link to clipboard
Copied
Hi, this is very useful script but I want to move placed PDFs in the pages not the text frame. Could you please help me on this?
Copy link to clipboard
Copied
Thank you! This just saved me a lot of time!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now