Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Indesign script to change the x and y coordinates of page items

Community Beginner ,
Sep 26, 2016 Sep 26, 2016

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

TOPICS
Scripting
3.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 26, 2016 Sep 26, 2016

Yes there is a way to do this. 😃

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 26, 2016 Sep 26, 2016

… 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! ]

(^/) 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 26, 2016 Sep 26, 2016

Still not a great master of UI! 

Capture d’écran 2016-09-27 à 14.14.10.png

Capture d’écran 2016-09-27 à 14.14.23.png

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]);

     }

}

(^/)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 27, 2016 Sep 27, 2016

This was extremely helpful!

Thank you very much! I can’t figure out a way to mark your answer as correct, otherwise I would.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 27, 2016 Sep 27, 2016

You're welcome!  It was funny (and interesting) to write and I would be truly interested by [JS] Masters' comments!

(^/) 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 29, 2016 Sep 29, 2016

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 30, 2016 Sep 30, 2016

I guess Equalizer might be of some help here…

http://www.indiscripts.com/blog/public/scripts/en_Equalizer-Manual.pdf

Best,

Marc

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 02, 2016 Oct 02, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 04, 2016 Oct 04, 2016

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 28, 2018 Jan 28, 2018

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 31, 2018 Jan 31, 2018
LATEST

Thank you!  This just saved me a lot of time!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines