Skip to main content
Inspiring
August 17, 2015
Answered

[CS6] Select text frame with a certain height and move it to a specific location?

  • August 17, 2015
  • 1 reply
  • 1090 views

I have a bunch of page labels I need to move. All of these labels are the same height (0.125 in) so what I'm thinking is that a script could go on each page and find the item based on that, select it, and finally move it to a specific XY location with a top right anchor point. Would this be very hard to do? I feel like this would be a rather simple script.

Thanks for any help you can give!

This topic has been closed for replies.
Correct answer Peter Kahrel

No problem getting the height of a selected frame and looking for frames with the same height. Here a sample script:

(function(){

  

    function frameHeight (frame) {

        var gb = frame.geometricBounds;

        return (gb[2]-gb[0]).toFixed(3);

    }

    function moveFrames (h) {

        var pItems = app.documents[0].pageItems.everyItem().getElements();

        for (var i = pItems.length-1; i >= 0; i--) {

            if (frameHeight (pItems) === h) {

                pItems.move ([0,0]);

            }

        }

    }

    if (app.selection.length > 0 && app.selection[0].hasOwnProperty('geometricBounds')) {

        var h = frameHeight (app.selection[0]);

        moveFrames (h);

    }

}());

This one move page items with the same height as the selected frame to the top left of the page; see the move() command in line 12. You can replace [0,0] with your own coordinates.

1 reply

Peter Kahrel
Community Expert
Community Expert
August 18, 2015

> I have a bunch of page labels I need to move. All of these labels are the same height (0.125 in)

Do you mean 'I have a bunch of page items [text frames, rectangles, etc.] with a particular label I need to move' or 'I have a bunch of page items 0.125 in tall that I need to move'?

Peter

ShaunreAuthor
Inspiring
August 18, 2015

EDIT: Sorry I think I misread your question. I have a bunch of page items of X height and I would like to select just those and move them.

Also I just got another idea. Would it be too hard to make it so that instead making the height set in the coding, it will instead grab the height from the current selected item and then simply search all pages for that height?

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
August 18, 2015

No problem getting the height of a selected frame and looking for frames with the same height. Here a sample script:

(function(){

  

    function frameHeight (frame) {

        var gb = frame.geometricBounds;

        return (gb[2]-gb[0]).toFixed(3);

    }

    function moveFrames (h) {

        var pItems = app.documents[0].pageItems.everyItem().getElements();

        for (var i = pItems.length-1; i >= 0; i--) {

            if (frameHeight (pItems) === h) {

                pItems.move ([0,0]);

            }

        }

    }

    if (app.selection.length > 0 && app.selection[0].hasOwnProperty('geometricBounds')) {

        var h = frameHeight (app.selection[0]);

        moveFrames (h);

    }

}());

This one move page items with the same height as the selected frame to the top left of the page; see the move() command in line 12. You can replace [0,0] with your own coordinates.