Skip to main content
Participant
March 8, 2019
Answered

Duplicate and move objects for a specific number of pages

  • March 8, 2019
  • 2 replies
  • 1985 views

I have an editorial project where I need to duplicate rectangular print marks at the edges of the pages. Every 16 pages this mark should move as far as its height (5mm) nd duplicate for another 16 pages, repeating this process until you finish the amount of pages of the project. As I am still learning to program in JavaScrip I would like to know if I can get any help with writing this code. I know I need to use the duplicate function for a rectangle but I do not know how to loop this action for 16 pages and move the object on the next page. Can someone help me?

This topic has been closed for replies.
Correct answer xxxxxxxxxxxxxxxxxxxxyyyy

Hi,

regarding the first problem:

you need to figure out how much the distance is that the printing mark needs to be moved on the even numbered pages. It should be a negative value. Then go to line 18 in the modiefied script and replace "enter your value here" with your value.

I don't have a solution by now how to get that distance value automatically.

Regarding the second problem:

That issue was caused by the if statement

if (m > pages.length-1 || (rectHeight * offset) > pages.bounds[3]) {break;}

It was supposed to stop the loop when

- it reaches the end of the document or

- when the printing mark would be moved off the page

Somehow the second condition doesn't work properly. I don't have a quick solution for this. So the script will no longer check whether or not the mark will be moved off the page.

Here's the modified code:

var doc = app.activeDocument;

var pages =doc.pages;

var rect = pages.firstItem().rectangles.firstItem();

var rectHeight = (rect.geometricBounds[2] - rect.geometricBounds[0]);

var offset = 0;

for (var i = 0; i < pages.length; i+=16)

    {

        for (var k = 0; k < 16; k++)

            {

                m = k + i;

              

                if (m % 2 == 0)

                    {

                        horizontalOffset = 0;

                    } else {horizontalOffset = "enter your value here"}

              

                if (m > pages.length-1) {break;}

              

                rect.duplicate(doc.pages, [horizontalOffset, rectHeight * offset]);

            }

        offset++;

    }

rect.remove();

2 replies

xxxxxxxxxxxxxxxxxxxxyyyy
Participating Frequently
March 8, 2019

Maybe something like this?

I tested this example script on a document that has only one single rectangle on the first page.

var doc = app.activeDocument;

var pages =doc.pages;

var rect = pages.firstItem().rectangles.firstItem();

var rectHeight = (rect.geometricBounds[0] - rect.geometricBounds[2] ) * -1;

var offset = 0;

for (var i = 0; i < pages.length; i+=16)

    {

        for (var k = 0; k < 16; k++)

            {

                m = k + i;

                if (m > pages.length-1 || (rectHeight * offset) > pages.bounds[3]) {break;}

                rect.duplicate(doc.pages, [0, rectHeight * offset]);

            }

        offset++;

    }

rect.remove();

alfredohdAuthor
Participant
March 10, 2019

Many thanks @crazyPanda. Your code is almost what I need. Thank you very much. But there are two issues to be solved. The first issue is that when I duplicate the mark to the next page it has to be aligned with the inside edge of the document (see the pictures). The second issue is that the marks have been duplicated only halfway through the pages of the document. How can I make them duplicate until I find the last page of the document? Again I really appreciate your help. See you.

alfredohdAuthor
Participant
March 11, 2019

Hi,

regarding the first problem:

you need to figure out how much the distance is that the printing mark needs to be moved on the even numbered pages. It should be a negative value. Then go to line 18 in the modiefied script and replace "enter your value here" with your value.

I don't have a solution by now how to get that distance value automatically.

Regarding the second problem:

That issue was caused by the if statement

if (m > pages.length-1 || (rectHeight * offset) > pages.bounds[3]) {break;}

It was supposed to stop the loop when

- it reaches the end of the document or

- when the printing mark would be moved off the page

Somehow the second condition doesn't work properly. I don't have a quick solution for this. So the script will no longer check whether or not the mark will be moved off the page.

Here's the modified code:

var doc = app.activeDocument;

var pages =doc.pages;

var rect = pages.firstItem().rectangles.firstItem();

var rectHeight = (rect.geometricBounds[2] - rect.geometricBounds[0]);

var offset = 0;

for (var i = 0; i < pages.length; i+=16)

    {

        for (var k = 0; k < 16; k++)

            {

                m = k + i;

              

                if (m % 2 == 0)

                    {

                        horizontalOffset = 0;

                    } else {horizontalOffset = "enter your value here"}

              

                if (m > pages.length-1) {break;}

              

                rect.duplicate(doc.pages, [horizontalOffset, rectHeight * offset]);

            }

        offset++;

    }

rect.remove();


Both problems were solved. The script worked perfectly. Many thanks for your help @crazyPanda, I will delve deeper into studying JavaScript to also be able to help other people. See you.

Inspiring
March 8, 2019

Hi,

     Set the document measurement units to Millimeters and then try like this. Use geometricbounds value according to your needs.

var rect = app.activeDocument.rectangles.add();

rect.geometricBounds = [0,0,5,5];

rect.fillColor = "Black";

var dupObj = rect.duplicate();

var nxtPg = app.activeDocument.pages[1];

dupObj.move(nxtPg);

alfredohdAuthor
Participant
March 10, 2019

Thanks for your response Sudha K . Your code helped me understand the fundamentals of JavaScript for Indesign and assume I was able to research more about how to develop the code abrogator.