Mobile app version of vmapp.org
Login or Join
Samaraweera207

: 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

@Samaraweera207

Posted in: #AdobeIndesign #Automation #IndesignScripting #Layers

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

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Samaraweera207

2 Comments

Sorted by latest first Latest Oldest Best

 

@Phylliss782

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

10% popularity Vote Up Vote Down


 

@Berryessa866

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme