Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to duplicate three rectangles at once without grouping?

Explorer ,
Jan 13, 2016 Jan 13, 2016

How to duplicate three rectangles at once without grouping?

Each rectangle is on a different layer.

Duplicate a rectangle at a time I can, but not that way.

I will duplicate the rectangles in the second document.

At most I could like this: (But it can not be so because it has to be specific rectangles.)

        function ItemByRange(){

            var sourcepage = app.documents[0].pages[0]; 

            var destpage = app.documents[1].pages[0]; 

            sourcepage.pageItems.itemByRange(app.documents[0].pages[0].rectangles[1], app.documents[0].pages[0].rectangles[4]).duplicate(destpage); 

            }

I use InDesign CS6 and CC, JSX, .vbs. Mac and PC.

Thank you!

TOPICS
Scripting
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Jan 15, 2016 Jan 15, 2016

Hi,

I tried other ways but always appears a problem.

This is the result

I wrote that way not to have problems positioning objects between them and their layers.

Example using three labels:

var findLabels = new Array("Name","Photo","Company");

var joinLb = findLabels.join();

var result = myAttempt_18 (joinLb);

alert("Duplicate objects: " + result);

function myAttempt_18(joinLabels){

    var resultLength = 0;

  

    var sourceDoc = app.documents[0];

    var sourceObj;

  

    var destDoc = app.docum

...
Translate
Explorer ,
Jan 14, 2016 Jan 14, 2016

I'm working on this code, but also failed.

myAttempt_14();    

function myAttempt_14(){

    var sourceDoc = app.documents[0];

    var destpage = app.documents[1].pages[0];

    var myRectamgle1 =  sourceDoc.pages[0].pageItems[0];

    var myRectamgle2 =  sourceDoc.pages[0].pageItems[1];

    var myRectamgle7 =  sourceDoc.pages[0].pageItems[6];

    var myObjs  = new Array();

    myObjs.push (myRectamgle1);

    myObjs.push (myRectamgle2);

    myObjs.push (myRectamgle7);

    sourceDoc.select(myObjs, SelectionOptions.addTo);

//~ The following code is wrong.

    sourceDoc.selection.itemByRange(sourceDoc.selection[0],sourceDoc.selection.length-1).duplicate(destpage);

//~ It is in this line I'm working on now. I'm trying.

    }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 14, 2016 Jan 14, 2016

Hi,

Why to duplicate "at once" is so important for you?

Jarek

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 14, 2016 Jan 14, 2016

Hi Jarek,

It is not very important, but it would be interesting.

In fact what is important to me:

Duplicate a set of objects (Rectangles, TextFrames, lines, images, groups) to the second document without changing the position between them.

However, each item is different layer. And that I also have to preserve.

In the second document the set will have a new position (on top of page, eg [0,0]).

Summing up

When duplicate:

  1. Maintaining the position of the objects between them.
  2. Keep each item in your layer
  3. Move the set of objects for a new position on the page of the second document.

Elvis

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 14, 2016 Jan 14, 2016

I second Jarek's comment.

But if you one stupid way of doing it would be app.copy() and app.paste();

But then all 3 would go onto the same layer in the target document which is probably not what you want.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 14, 2016 Jan 14, 2016

Here I have the preference set,  "Paste Remembers Layers" to get around this. Some snippets I place have to go to specific layers, and this solves that too. I don't know what it would be in code but that may solve the layer issue. I don't recall if that was an option in CS6.

Screen Shot 2016-01-14 at 10.48.14 AM.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 13, 2016 Feb 13, 2016
LATEST

Hi Mikie9

Sorry I have not answered before.

Your answer helped me a lot.

Thank you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 14, 2016 Jan 14, 2016

Hi,

Until then I think the best way is:

  1. List the layers of each selected item.
  2. Group selected objects.
  3. Move to the second document.
  4. Ungroup them.
  5. Move each item to its respective layer.

I not tried it yet because I was looking for a better way.

I just hope that the objects remain in the order. Because it may have the same label.

Of course, it will check if the "Paste Remembers Layers" can help.

I will trying other forms until exhausted.

Elvis

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 14, 2016 Jan 14, 2016

Hi,

How it works on your side?

var

  cObj = app.selection[0],

  sourceIdx = cObj.parentPage.parent.index,

  targetDoc = app.documents[1],

  targetSpread = targetDoc.spreads[sourceIdx];

  cObj.duplicate(targetSpread);

Assumings:

  • 2 doc opened
  • both have the same page structure (not necessary the same layers)
  • object to be duplicated - is selected

Is destination layer created and object duplicated correctly?

Jarek

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 15, 2016 Jan 15, 2016

Hi,

It is not just an object that will be duplicated but several.

I wrote this question with three sample rectangles to simplify the question.

Elvis

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 15, 2016 Jan 15, 2016

...

It is not just an object that will be duplicated but several.

I wrote this question with three sample rectangles to simplify the question.

I wrote this sample of code to simplify the answer

Jarek

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 15, 2016 Jan 15, 2016

Hi,

I tried other ways but always appears a problem.

This is the result

I wrote that way not to have problems positioning objects between them and their layers.

Example using three labels:

var findLabels = new Array("Name","Photo","Company");

var joinLb = findLabels.join();

var result = myAttempt_18 (joinLb);

alert("Duplicate objects: " + result);

function myAttempt_18(joinLabels){

    var resultLength = 0;

  

    var sourceDoc = app.documents[0];

    var sourceObj;

  

    var destDoc = app.documents[1];

    var destpage = destDoc.pages[0];

    var destSameLayer = new Array();

    var destArrayObjs = new Array();

    var duplicateObj;

    with (sourceDoc.pages[0]){

        for (var h = pageItems.length-1; h >= 0; h --){

            sourceObj = pageItems;

            if (sourceObj.label != ""){

                if (joinLabels.indexOf(sourceObj.label) > -1 ){

                  duplicateObj =  sourceObj.duplicate(destpage);

                  destArrayObjs.push(duplicateObj);

                  destSameLayer.push(sourceObj.itemLayer.name);

                    }

                }

            }

        }

  

    if (destArrayObjs.length > 0 ){

        resultLength = destArrayObjs.length;

        destDoc.select(destArrayObjs, SelectionOptions.replaceWith);

        destGroup = destDoc.groups.add(destDoc.selection);

        destGroup.move ([0,0]);

        destDoc.select (destDoc.selection, SelectionOptions.removeFrom);

        destGroup.ungroup();

        for (var L = 0; L < destArrayObjs.length; L ++){

            destArrayObjs.move (destDoc.layers.item(destSameLayer));

            }

        }

      return resultLength;

    }

This script will be part of another larger script.

The code is not beautiful, but you can use.

Link of the document that I tested. (www.wetransfer.com)

http://we.tl/6gpfa3zC2W

Elvis

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 15, 2016 Jan 15, 2016

I'll leave as a correct answer.

I do not know if there's another way better.

Elvis

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