Copy link to clipboard
Copied
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!
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
Copy link to clipboard
Copied
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.
}
Copy link to clipboard
Copied
Hi,
Why to duplicate "at once" is so important for you?
Jarek
Copy link to clipboard
Copied
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:
Elvis
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.

Copy link to clipboard
Copied
Hi Mikie9
Sorry I have not answered before.
Your answer helped me a lot.
Thank you.
Copy link to clipboard
Copied
Hi,
Until then I think the best way is:
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
Copy link to clipboard
Copied
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:
Is destination layer created and object duplicated correctly?
Jarek
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
...
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
Copy link to clipboard
Copied
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)
Elvis
Copy link to clipboard
Copied
I'll leave as a correct answer.
I do not know if there's another way better.
Elvis
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more