Move all contents from 1 frame to another

Advocate ,
Jun 02, 2022 Jun 02, 2022

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

355

Likes

Translate

Translate

Report

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

Adobe Community Professional , Jun 02, 2022 Jun 02, 2022
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 = { ...

Likes

Translate

Translate
Adobe Community Professional ,
Jun 02, 2022 Jun 02, 2022

Copy link to clipboard

Copied

I think you can do it without script as fast as with script. 

  1. Open the Layer Panel,
  2. you can expand the layers and see what groups, subgroups and objects are on the active spread. (Not what is seen from the master/parent page)
  3. Select the items you want to move (you can select on the pages, but also on the layer panel) 
  4. and move either the colored proxy square right from the item or the item itself (both in the Layer Panel) and move it to the destination.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jun 02, 2022 Jun 02, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jun 02, 2022 Jun 02, 2022

Copy link to clipboard

Copied

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');

Likes

Translate

Translate

Report

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
Advocate ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

LATEST

This worked like a charm Thank you very much. And thank everyone else who helped.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jun 03, 2022 Jun 03, 2022

Copy link to clipboard

Copied

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 )

Likes

Translate

Translate

Report

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
Advocate ,
Jun 06, 2022 Jun 06, 2022

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

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 )

Likes

Translate

Translate

Report

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
Advocate ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

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 )

 

Likes

Translate

Translate

Report

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
Advocate ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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