Copier le lien dans le Presse-papiers
Copié
Is there a script somewhere that allows you to move all contents from 1 layer to antoher? ex.. Layer 1 to Defalut? I have a script that creates a layer and adds a text frame to it but i cannot figure how to move everyting from that frame to a different one.
Thanks as usual
Chris
Hi @cbishop01, I wrote this script to show you the way to move page items from layer to another. It seems simple but I had to pay attention to the order I did things in (including sorting by page number). Hopefully it will be enough to progress your script.
- Mark
/*
Move Contents of Layer.js
for Adobe Indesign 2022
by m1b
discussion here: https://community.adobe.com/t5/indesign-discussions/move-all-contents-from-1-frame-to-another/m-p/12981521#M479445
*/
var settings = {
...
Merge is how the Designer is doing it now. Kind of fixing what was done wrong. I was just trying to make it easier where once he opens the document the eventlistener would start the script automating the process.
Copier le lien dans le Presse-papiers
Copié
I think you can do it without script as fast as with script.
Copier le lien dans le Presse-papiers
Copié
Yes you are right @Willi Adelberger, and it's always best to look for the simplest solution. My thought was that the OP needs to incorporate the functionality into an existing script workflow. Also the standard UI approach doesn't seem to work across multiple pages.
- Mark
Copier le lien dans le Presse-papiers
Copié
Hi @cbishop01, I wrote this script to show you the way to move page items from layer to another. It seems simple but I had to pay attention to the order I did things in (including sorting by page number). Hopefully it will be enough to progress your script.
- Mark
/*
Move Contents of Layer.js
for Adobe Indesign 2022
by m1b
discussion here: https://community.adobe.com/t5/indesign-discussions/move-all-contents-from-1-frame-to-another/m-p/12981521#M479445
*/
var settings = {
sourceLayerName: 'Layer 1',
destinationLayerName: 'Layer 2'
}
function main() {
var doc = app.activeDocument,
sourceLayer = layer(doc, settings.sourceLayerName),
destinationLayer = layer(doc, settings.destinationLayerName),
layerItems = sourceLayer.pageItems,
itemsToMove = [];
for (var i = layerItems.length - 1; i >= 0; i--)
itemsToMove[i] = layerItems[i];
itemsToMove.sort(function (a, b) { return b.parentPage.documentOffset - a.parentPage.documentOffset });
for (var i = itemsToMove.length - 1; i >= 0; i--)
itemsToMove[i].move(destinationLayer);
alert('Moved ' + itemsToMove.length + ' items\nfrom layer "' + settings.sourceLayerName + '" to layer "' + settings.destinationLayerName + '".');
} // end main
function layer(doc, name) {
var layer = doc.layers.itemByName(name);
if (!layer.isValid)
layer = doc.layers.add({ name: name });
return layer;
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Move Contents Of Layer');
Copier le lien dans le Presse-papiers
Copié
This worked like a charm Thank you very much. And thank everyone else who helped.
Copier le lien dans le Presse-papiers
Copié
Hi Chris,
I'm not really sure what you are asking here.
"I have a script that creates a layer and adds a text frame to it but i cannot figure how to move everyting from that frame to a different one."
How would you define or recognize the text frame where you want to move everything to?
With "everything from that frame", do you mean the formatted contents? The text and maybe also anchored objects?
Is this target text frame selected before you run your script? Is it still selected after you ran your script?
Let's suppose it is selected and your newly added text frame is in variable myNewTextFrame you could add the following code to this other script:
myNewTextFrame.parentStory.texts[0].move
(
LocationOptions.AT_BEGINNING ,
app.selection[0].insertionPoints[0]
);
Or do you want to simply move the text frame that your script is adding to a new layer? And if so, which one? What exactly do you mean with "default layer" ?
If it is the currently active layer simply add this code to your script where variable myNewTextFrame contains the text frame that your script is adding:
myNewTextFrame.itemLayer = app.documents[0].activeLayer;
Regards,
Uwe Laubender
( Adobe Community Professional )
Copier le lien dans le Presse-papiers
Copié
I havent tried any of these scripts yet i'll try and check them out tomorrow. What i was doing it Having a Script delete a "named text frame" from a layer. then i was going to have anything that was left in that layer move to a different layer. Whats happened is there are several files where the Designer wasnt paying attention and placed all kinds of Art, Text frames, Guides etc... in the wrong layer. So by moving everything out of that layer we clean up the documents a little more. and keep items where they need to be. I hope i am making sense?
Copier le lien dans le Presse-papiers
Copié
My lines of code are no full scripts. They only show ways to expand your script you mentioned in your first post here. Now with your last answer I am totally confused what you like to do and already done. Is the title of this thread perhaps meant as: "Move all contents from 1 frame layer to another" ?
Regards,
Uwe Laubender
( Adobe Community Professional )
Copier le lien dans le Presse-papiers
Copié
I'm following now! and Yes i titled it wrong sorry. I'll see if I can change the name. i meant move everything from 1 layer to another.
Copier le lien dans le Presse-papiers
Copié
Hi Chris,
did you consider the option to merge layers?
If you need all items on one layer on a different one and you do not need that now empty layer not more the best option you have is to merge layers. A simple option in the Layers panel. First select the layer that should remain, then the one you like to merge with that layer. Next use the option in the Layers panel to merge the two.
Could also be scripted, but I cannot tell exactly how, because I do not understand the state of your document after you ran that mentioned script.
Regards,
Uwe Laubender
( Adobe Community Professional )
Copier le lien dans le Presse-papiers
Copié
Merge is how the Designer is doing it now. Kind of fixing what was done wrong. I was just trying to make it easier where once he opens the document the eventlistener would start the script automating the process.
Copier le lien dans le Presse-papiers
Copié
perfect answer
Trouvez plus d’idées, d’événements et de ressources dans la nouvelle communauté Adobe
Explorer maintenant