: InDesign: script to "paste in place" selected objects to all unlocked layers I am trying to build a script to "paste in place" all selected objects to all unlocked layers. My attempt is probably
I am trying to build a script to "paste in place" all selected objects to all unlocked layers. My attempt is probably nearly there, but something's not working.
var myDoc = app.activeDocument;
var al=myDoc.activeLayer.name; // remembers current layer name
app.copy(); // copies whatever is selected
// paste in place for all unlocked layers, excepting source layer
for (var i=0;i<myDoc.layers.length;i++) {
if ((myDoc.layers[i].locked=false) && (myDoc.layers[i].name!=al)) {
myDoc.activeLayer=myDoc.layers[i];
app.pasteInPlace();
}
}
More posts by @Samaraweera207
2 Comments
Sorted by latest first Latest Oldest Best
Variant script to paste in place selected objects on all other locked layers:
var myDoc = app.activeDocument;
var al=myDoc.activeLayer.name; // remembers current layer
app.copy(); // copies whatever is selected
for (var i=0;i<myDoc.layers.length;i++) {
if ((myDoc.layers[i].locked==true) && (myDoc.layers[i].name!=al)) {
myDoc.activeLayer=myDoc.layers[i]; // select next layer
myDoc.layers[i].locked=false; // unlock it
app.pasteInPlace(); // paste in place
myDoc.layers[i].locked=true; // relock it
}
}
myDoc.activeLayer=al; // Go back to original layer
Your check if the layer is locked is missing a = (it's assigning rather than evaluating otherwise). It should be;
if ( myDoc.layers[i].locked == false ) ...
I just tested and the script works perfectly with that corrected.
The full working script is then:
var myDoc = app.activeDocument;
var al = myDoc.activeLayer.name; // remembers current layer name
app.copy(); // copies whatever is selected
// paste in place for all unlocked layers, excepting source layer
for ( var i = 0; i < myDoc.layers.length; i++ ) {
if ( myDoc.layers[i].locked == false && myDoc.layers[i].name != al ) {
myDoc.activeLayer = myDoc.layers[i];
app.pasteInPlace();
}
}
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.