Copy link to clipboard
Copied
Hi everybody,
I am currently working on a template for our booklets for competitions and I am struggling with automatic numbering. The intention is to place a caption under each image that automatically numbers. Placing the caption and the custom paragraph style that ensures the numbering is not a problem, but the order of the numbers goes wrong. I have already read that numbering is done based on the order in which the images are placed, but I'm looking for a way to number the images continuously from left to right, top to bottom. Is there a way to do this? Even when inserting a picture in between, the numbering should go well. They are often pages that only contain images.
Thanks for the info!
Hi Danielle:
Here's a way to make it work the way you want... add a text frame on the page, and then anchor the frames to the ¶. This will a.) force the anchored frames to number in the order of the anchors and b.) if you move the anchors or add a new anchored frame in the middle, it will force them to renumber, and re-wrap.
Anchors can be confusing, so a less-elegant way that will still work is to paste them as inline graphics and use tabs to separate them. Use Story Editor to rearrange the ancho
...Copy link to clipboard
Copied
If you want to use a paragraph style with a numbered list for the caption your only choice is to copy/paste in place all the images in the right order.
Copy link to clipboard
Copied
But there is another way without the use of a paragraph style or am I getting your answer wrong?
Copy link to clipboard
Copied
I would love to know! I have the same problem too!
Maybe some plug-in can help but in all these years I have not found an integrated solution in Indesing yet.
Copy link to clipboard
Copied
AFAIK InDesign frame ordering is not a "left to right, top to bottom", but some as "by date of creation".
Trick: сut&paste the frame and this frame will be "the latest" on the page.
Copy link to clipboard
Copied
Hi Danielle:
Here's a way to make it work the way you want... add a text frame on the page, and then anchor the frames to the ¶. This will a.) force the anchored frames to number in the order of the anchors and b.) if you move the anchors or add a new anchored frame in the middle, it will force them to renumber, and re-wrap.
Anchors can be confusing, so a less-elegant way that will still work is to paste them as inline graphics and use tabs to separate them. Use Story Editor to rearrange the anchors and they will renumber in Layout view.
~Barb
Copy link to clipboard
Copied
Hi there
I found this question interesting and tried to write a script that would "rearrange" the frames.
It is very experimental (I'm a scripting beginner) so run in on a copy of your document.
Important: Change line 2 to replace "numbered" by your numbered list paragraph style.
Any feedback appreciated!
var myDocument = app.documents.item(0);
var myParaStyle = "numbered";
var myFrames = [];
//create collection
for (i = 0; i < myDocument.textFrames.length; i++) {
if (myDocument.textFrames.paragraphs[0].appliedParagraphStyle.name == myParaStyle) {
myFrames.push(myDocument.textFrames);
}
}
//sort collection
function sortFramesinArray(a, b) {
if (Math.round(a.geometricBounds[1]) === Math.round(b.geometricBounds[1])) {
return Math.round(a.geometricBounds[0]) - Math.round(b.geometricBounds[0]);
}
return Math.round(a.geometricBounds[1]) - Math.round(b.geometricBounds[1]);
}
myFrames.sort(sortFramesinArray);
// cut and paste in place
for (i = 0; i < myFrames.length; i++) {
myFrames.select();
app.cut();
app.pasteInPlace();
}
Vinny
Copy link to clipboard
Copied
Hi Vinny,
Can you explain me how i could put the script in Indesign? I'm not used to work with them. Is it possible to order them from left to right and then top to bottom?
Thanks!
Copy link to clipboard
Copied
Hi Vinnie,
I found out how to run the script but I get an error.
Copy link to clipboard
Copied
Hi Danielle.
Hummm... That wasn't really the expected result...
I'm really not too sure about this "Object is Invalid" error. So I will post a request on the Indesign scripting forum.
I tested it on CS6 but I can see you use Indd 7.5 (CS5.5). Maybe that's why an error is thrown.
Could you create a very basic document with only a couple of text frames with "numbered" paragraph style applied and run the script again? Just to check whether it's a document issue or an environment one.
Let me know...
Vinny
Copy link to clipboard
Copied
Hi Vinny,
I've tried it with just text blocks and it works! I used the same paragraph style as before, the only difference with the previous test is that the textframes are automatically generated captions. Maybe that's the problem?
Thanks for the effort!
Copy link to clipboard
Copied
Hi Vinny,
I've just tested it with captions and it works! I think the problem was that the captions were grouped to the image, could that be? When I ungroup them it works fine!
Could I just ask for one adjustment? At the moment the numbering runs first from top to bottom and then from left to right, but for us it would be more convenient to run first from left to right and then from top to bottom. Is it possible to adjust this?
Copy link to clipboard
Copied
Hi Danielle.
As a matter of fact, groups can be troublemakers as the script did not support them.
So please find below a new version of the script where an "ungroup everything" function was added.
Also, I did add an Dialog box where you can directly pick your paragraph style (no need to change the script) and sorting direction (top to bottom or left to right).
Let me know if it works for you:
//Reorder unthreaded text frames with numbered list
//Written by Vinny
if (app.documents.length > 0) {
var myDocument = app.documents[0];
//----------------------------ungroup all----------------------------
function unGroup() {
with(myDocument) {
while (groups.length != 0) {
groups.everyItem().ungroup();
}
}
}
unGroup();
//----------------------------Open Dialog box:---------------------------
var myStylesNames = [];
for (i = 0; i < myDocument.allParagraphStyles.length; i++) {
myStylesNames.push(myDocument.allParagraphStyles.name);
}
var myDialog = app.dialogs.add({
name: "Reorder unthreaded text frames with numbered list",
canCancel: true
});
with(myDialog.dialogColumns.add()) {
staticTexts.add({
staticLabel: "Choose your numbered paragraph style:"
});
}
with(myDialog.dialogColumns.add()) {
var myDDSTyles = dropdowns.add({
stringList: myStylesNames,
selectedIndex: 0
});
}
with(myDialog.dialogColumns.add()) {
staticTexts.add({
staticLabel: "Sort frames from:"
});
}
with(myDialog.dialogColumns.add()) {
var myOrientations = ["Left to right", "Top to bottom"];
var myDDOrientation = dropdowns.add({
stringList: myOrientations,
selectedIndex: 0
});
}
var myResult = myDialog.show();
if (myResult == true) {
var myParaStyle = myStylesNames[myDDSTyles.selectedIndex];
var myOrientation = myOrientations[myDDOrientation.selectedIndex];
}
myDialog.destroy();
//---------------------------create collection ---------------------------
var myFrames = [];
for (i = 0; i < myDocument.textFrames.length; i++) {
if (myDocument.textFrames.contents.length > 0) {
if (myDocument.textFrames.paragraphs[0].appliedParagraphStyle.name == myParaStyle) {
myFrames.push(myDocument.textFrames);
}
}
}
//---------------------------sort collection ---------------------------
function sortLTR(a, b) {
if (Math.round(a.geometricBounds[0]) === Math.round(b.geometricBounds[0])) {
return Math.round(a.geometricBounds[1]) - Math.round(b.geometricBounds[1]);
}
return Math.round(a.geometricBounds[0]) - Math.round(b.geometricBounds[0]);
}
function sortTTB(a, b) {
if (Math.round(a.geometricBounds[1]) === Math.round(b.geometricBounds[1])) {
return Math.round(a.geometricBounds[0]) - Math.round(b.geometricBounds[0]);
}
return Math.round(a.geometricBounds[1]) - Math.round(b.geometricBounds[1]);
}
if (myOrientation == "Left to right") {
myFrames.sort(sortLTR);
} else {
myFrames.sort(sortTTB);
}
// ---------------------------cut and paste in place ---------------------------
for (i = 0; i < myFrames.length; i++) {
myFrames.select();
app.cut();
app.pasteInPlace();
}
} else {
alert("Please open a document first then run the script…");
}
Edit: Added a "check if there's at least one opened document" (Thanks to LoicAigon's hawk-eye)
Also I noticed that empty text frames were causing an error. So I added a condition to work around this issue.
Copy link to clipboard
Copied
Hi Vinny,
Thank you so much for your effort! The menu for the paragraph style and the organization is super! Unfortionally I get another Error when I run it through my document.
Copy link to clipboard
Copied
Danielle,
can you share your document so I can try to find what causes the error?
(Dropbox, Wetransfer, etc.)
Cheers