Highlighted

automatic numbering gone wrong

Explorer ,
Jan 17, 2018

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!

Adobe Community Professional
Correct answer by Barb Binder | Adobe Community Professional

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

Screenshot 2018-01-17 10.21.30.png

Views

709

Likes

Translate

Translate

Report

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

automatic numbering gone wrong

Explorer ,
Jan 17, 2018

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!

Adobe Community Professional
Correct answer by Barb Binder | Adobe Community Professional

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

Screenshot 2018-01-17 10.21.30.png

Views

710

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jan 17, 2018 0
Participant ,
Jan 17, 2018

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 17, 2018 0
Explorer ,
Jan 17, 2018

Copy link to clipboard

Copied

But there is another way without the use of a paragraph style or am I getting your answer wrong?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 17, 2018 0
Participant ,
Jan 17, 2018

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 17, 2018 0
Adobe Community Professional ,
Jan 17, 2018

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 17, 2018 0
Adobe Community Professional ,
Jan 17, 2018

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

Screenshot 2018-01-17 10.21.30.png

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 17, 2018 3
Guide ,
Jan 19, 2018

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

}

sort.gif

Vinny

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 19, 2018 2
Explorer ,
Jan 19, 2018

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!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 19, 2018 0
Explorer ,
Jan 19, 2018

Copy link to clipboard

Copied

Hi Vinnie,

I found out how to run the script but I get an error.

error script.PNG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 19, 2018 0
Guide ,
Jan 22, 2018

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 22, 2018 1
Explorer ,
Jan 22, 2018

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!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 22, 2018 0
Explorer ,
Jan 22, 2018

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?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 22, 2018 0
Guide ,
Jan 22, 2018

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 22, 2018 1
Explorer ,
Jan 23, 2018

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.

error script2.PNG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 23, 2018 0
vinny38 LATEST
Guide ,
Jan 23, 2018

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 23, 2018 0