Skip to main content
December 29, 2016
Answered

find text frame behind rectange

  • December 29, 2016
  • 4 replies
  • 2013 views

how to group if any text frame behind rectangle frame.

This topic has been closed for replies.
Correct answer Trevor:

I have been in this forum for nearly 6 years.. this is how it works.. so guided you.. don't take it as personal..


This should help

Select the picky.

Trevor

// jshint undef: true, unused: true

var stopIfNot, picky, spread, spreadItems, l, itemsToTestForBounds, item, itemBounds, itemsToGroup, pickyBounds;

stopIfNot = function(condition, message) {

    if (!condition) {

        if (message) {

            alert(message);

        }

        exit();

    }

};

picky = spread = app.selection[0];

stopIfNot(spread, 'No Selection');

///////////////////////////

// Get the parent spread //

///////////////////////////

while (spread.constructor !== Spread) {

    spread = spread.parent;

    if (spread.constructor === Document) {

        spread = false;

        break;

    }

}

stopIfNot(spread, 'No Spread found');

///////////////////////////////////////////

// Get objects behind the selected order //

///////////////////////////////////////////

spreadItems = spread.allPageItems;

l = spreadItems.length - 1;

itemsToTestForBounds = [];

while ((item = spreadItems[l--]) !== picky) {

    if (item.parent.constructor !== Spread) {

        continue; // only want out objects

    }

    itemsToTestForBounds.push(item);

}

if (itemsToTestForBounds.length) {

    itemsToTestForBounds.push(picky);

}

itemsToGroup = [];

pickyBounds = picky.geometricBounds;

///////////////////////

// test for overlaps //

///////////////////////

l = itemsToTestForBounds.length;

while (l--) {

    item = itemsToTestForBounds;

    itemBounds = item.geometricBounds;

    if (!(itemBounds[0] > pickyBounds[2] ||

            itemBounds[2] < pickyBounds[0] ||

            itemBounds[1] > pickyBounds[3] ||

            itemBounds[3] < pickyBounds[1])) {

        itemsToGroup.push(item);

    }

}

////////////////////////////

// Group overlapped items //

////////////////////////////

newGroup = app.activeDocument.groups.add(itemsToGroup, picky.itemLayer);

4 replies

January 2, 2017

Now I am very clear. Thank you so much.

Community Expert
December 30, 2016

Hi Keyank,

Trevor's script is a very good start.

You have to adapt it to your needs:

1. Single out text frames. You can do this e.g. in line 33 or 34.

2. Currently the scope of the script is a selected item on the page.

Maybe you do not want to work with that, but perhaps with all graphic frames that contain images on a page.

Or on all pages of a spread. Or running a loop through all pages of your document and testing graphic frames that contain images …

3. You should add a try/catch around line 65.

itemsToGroup could only contain one item—the one you selected—if no item is found stacked behind the selected one.

Regards,
Uwe

Trevor:
Legend
December 30, 2016

Hi Uwe

It cant contain 1 item but it could contain none so could do

if (itemsToGroup.length) {newGroup = app.activeDocument.groups.add(itemsToGroup, picky.itemLayer)};

Trevor

Community Expert
January 2, 2017

Thanks for the hint, Trevor.

To Keyank:

Where is the problem?

There is no default function to find all items stacked below a selected item.

All we can tell is the stacking order of all page items in a spread.

Not in a page. In a spread. And that would also include items on the pasteboard.

spread.allPageItems is the array where the items are stored in stacking order.

From top to bottom.

Have a document with one page where an image is placed.

Stacked below is a text frame.

Run this snippet:

var spreadOneItems = app.documents[0].spreads[0].allPageItems;

for(var n=0;n<spreadOneItems.length;n++){$.writeln(n+"\t"+spreadOneItems)};

Result will be something like that:

0    [object Rectangle]

1    [object Image]

2    [object TextFrame]

Group all items on the spread—the rectangle (that contains the image) and the text frame stacked below—and run the snippet again.

Result will be:

0    [object Group]

1    [object Rectangle]

2    [object Image]

3    [object TextFrame]

Regards,
Uwe

December 30, 2016

There is no relation between image and credit text frame. But i need to find credit text frame and both to be grouped.

tpk1982
Legend
December 30, 2016

AS Uwe said, you have to check the geometric bounds for both image and text frame.. if it overlapped then need to group... the link he provided give the idea to proceed further

December 30, 2016

I used to place the image and caption in front of textframe using wrap property and i have one another text frame in front of image. I need to find only those credit frame and group along with caption and image. also i am going to export all things as image i wrote that concept.

when i export the same as image i need to include credit frame

Community Expert
December 30, 2016

Can you please be more specific?

Do you want to find text frames with captions or photographer's credits and the corresponding image?

Didn't we have something like that a few days before?

As a starter see here where Stefan Rakete gave the answer not to the same but to a similar problem:

Re: Find Image Name

Regards,

Uwe