Copy link to clipboard
Copied
how to group if any text frame behind rectangle frame.
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.construc
Copy link to clipboard
Copied
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:
Regards,
Uwe
Copy link to clipboard
Copied
There is no relation between image and credit text frame. But i need to find credit text frame and both to be grouped.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
I hope you aware about Live caption facility in indesign.. it will have option to give distance and grouping option..
http://layersmagazine.com/setting-up-live-captions-in-indesign-cs5.html
http://creativepro.com/automated-indesign-captions/
Using Live Captions in InDesign CS5 | Creative Bloq
Look this also.. have a script
http://indesignsecrets.com/easily-add-captions-to-graphics-frames.php
Copy link to clipboard
Copied
I need solution to find the textframe behind the graphic frame.
Copy link to clipboard
Copied
In this forum basically they will help you.. and not work for you.. try to write some codings and then ask help here.. definitely you will get answer from experts ..
Copy link to clipboard
Copied
Please don't take this other way. Thanks you so much karthi.
Copy link to clipboard
Copied
I have been in this forum for nearly 6 years.. this is how it works.. so guided you.. don't take it as personal..
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
I don't know how to do this. if there is any option to find the behind object in javascript
Copy link to clipboard
Copied
See the group caption with image option in right bottom corner
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
See line 39
Copy link to clipboard
Copied
Is there is any default function find the stack order ?
Copy link to clipboard
Copied
Hi
This would be a generic function for sorting an array of pageItems (all belonging to the same spread) by stack order.
// Order an array page items by z stacking order
// by Trevor http://creative-scripts.com
// jshint undef: true, unused: true
/* globals app, $, MeasurementUnits, ContentType, Spread, Document */
var orderByStack;
orderByStack = function(pageItems) {
var spread, allSpreadItems, n, c, item,
stackMap = [];
////////////////////////////////////////////////////////////////////////////////////////
// Get the parent spread //
// We're going to be lazy and not check that all the pageItems are on the same spread //
// If there not then a deserved error will be thrown //
////////////////////////////////////////////////////////////////////////////////////////
spread = pageItems[0];
while (spread.constructor !== Spread) {
spread = spread.parent;
if (spread.constructor === Document) {
spread = false;
return pageItems; // spit back the same spit that was spat
}
}
allSpreadItems = spread.allPageItems;
n = allSpreadItems.length;
//////////////////////////////////
// Index the spread items by Id //
//////////////////////////////////
for (c = 0; c < n; c++) {
item = allSpreadItems
; stackMap['_' + item.id] = {
index: c,
item: item
};
}
//////////////////////////////////////////////////////////////////////////////////
// make a temp non-sorted list of the pageItems that contains there stack index //
//////////////////////////////////////////////////////////////////////////////////
n = pageItems.length;
for (c = 0; c < n; c++) {
pageItems
= stackMap['_' + pageItems .id]; }
/////////////////////////////////////
// Sort the stackList by stack order //
/////////////////////////////////////
pageItems.sort(function(a, b) {
return b.index < a.index;
});
while (n--) {
pageItems
= pageItems .item; }
allSpreadItems.length = 0;
return pageItems;
};
/////////////////
// Pretty Demo //
/////////////////
var doc, itemsToCheck = [],
n, madeItems = [];
doc = app.documents.add({
viewPreferences: {
horizontalMeasurementUnits: MeasurementUnits.MILLIMETERS,
verticalMeasurementUnits: MeasurementUnits.MILLIMETERS
}
});
var swatchCount, itemsToMake, top, left, bottom, right, rn, item, s, rn, color;
swatchCount = doc.swatches.length - 1;
/////////////////////
// Make some items //
/////////////////////
itemsToMake = 15;
while (itemsToMake--) {
top = 10 + (260 * Math.random()) | 0;
left = 10 + (180 * Math.random()) | 0;
bottom = top + 40 + 100 * Math.random() | 0;
right = left + 40 + 100 * Math.random() | 0;
madeItems.push(doc.pages[0].rectangles.add({
geometricBounds: [top, left, bottom, right],
fillColor: 'None',
strokeColor: doc.swatches[-1],
transparencySettings: {
blendingSettings: {
opacity: 70
}
}
}));
}
////////////////////////////////
// randomly pick some of them //
////////////////////////////////
n = 5;
while (n--) {
rn = madeItems.length * Math.random() | 0;
itemsToCheck.push(madeItems[rn]);
madeItems.splice(rn, 1);
}
///////////////////////////////////////////////////////////
// we now have 5 items that are of a random stack order. //
// Let's order them //
///////////////////////////////////////////////////////////
orderByStack(itemsToCheck);
///////////////////////////
// Lets make them pretty //
///////////////////////////
n = itemsToCheck.length;
s = 0;
$.writeln('back');
while (n--) {
item = itemsToCheck
; s = s % swatchCount + 1;
color = doc.swatches[swatchCount - s];
item.fillColor = color;
item.contentType = ContentType.TEXT_TYPE;
item = item.getElements()[0];
item.contents = '' + (n + 1);
$.writeln('item.itemByID(' + item.id + ').color.name: ' + color.name + ' contents: ' + item.contents);
}
$.writeln('front');
Copy link to clipboard
Copied
Now I am very clear. Thank you so much.