Skip to main content
New Participant
July 5, 2024
Question

Error when trying to select two text frames from a layer with script (Error number: 53762)

  • July 5, 2024
  • 3 replies
  • 921 views

I am trying to create a script to select two text frames from a layer of a document so that I can copy them to another document. I managed to copy them one at a time, but I need to copy both at once because they are linked by a thread.

When I try to use the code below, I get the following error: "Error number: 53762 / Action is not enabled."

 

var layerName = "Nomes";
var sourceLayer = sourceDoc.layers.itemByName(layerName);
sourceDoc.activeLayer = sourceLayer;
var actionID = 18455;
app.menuActions.itemByID(actionID).invoke();

 

Action 18455 tries to select all items in the layer. I tried adding an action to open the layers menu before selecting them, but it made the software crash.

This topic has been closed for replies.

3 replies

Community Expert
July 7, 2024

Mark's point was (I think) that you shouldn't try to select those frames and go through menu actions, but refeerence those frames directly.

 

To copy the frames on the Nomes layer to another document, use this:

app.documents[0].layers.item('Nomes')
  .textFrames
  .everyItem()
  .duplicate (app.documents[1].pages[0]);

This assumes your one-page document. To copy the frames on a given page, collect the frames on that page on that layer and duplicate those. Placing them on a particular layer in the target document requires an additional step.

Community Expert
July 7, 2024

Forgot to mention that the copied frames will be unthreaded, you'll have to re-thread them after duplicating them. (Turns out that when you copy and paste them, the frames remain threaded. But that works only on a single page/spread.)

m1b
Community Expert
July 5, 2024

Hi @Breno25791737ot2o, this is a conventional approach, I think. Does it help in your case?

- Mark

function main() {

    var sourceDoc = app.activeDocument;
    var layerName = "Nomes";
    var sourceLayer = sourceDoc.layers.itemByName(layerName);

    if (!sourceLayer.isValid)
        return alert('No Layer called "' + layerName + '".');

    sourceLayer.locked = false;
    sourceLayer.visible = true;

    sourceDoc.selection = sourceLayer.textFrames;

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Your Script Name');
Robert at ID-Tasker
Brainiac
July 6, 2024

@m1b

 

It's not about selecting ALL TextFrames on a layer - but only ones that belong to a specified Story - and are on active page / spread.

 

m1b
Community Expert
July 6, 2024

Oh, sorry if I misunderstood.

 

@Breno25791737ot2o a good approach would be to post your sample document *before* the script and also the sample document *after* running the script. That way we can see exactly what you are wanting.

- Mark

Robert at ID-Tasker
Brainiac
July 5, 2024

Maybe your document is corrupted - try IDMLing - export as IDML, open, save with a new name - do not overwrite your original file.

 

You can't select objects on multiple spreads - only same page / spread.

 

If you can copy one-by-one - this means that neither layer or those objects are locked? 

 

What is the exact name of the action you are trying to invoke? 

 

New Participant
July 5, 2024

Hey, Robert!
It is a very simple document, with only one page, just for testing.
I'm trying to invoke 'Select Layer Items'.
Both textframes are on the same page, and they are not locked.

New Participant
July 5, 2024

Do you need to copy those TFs - in their currennt state - or do you need to just copy text contents?

 


I just need the text contents. I thought this way would be easier. Another alternative would be to copy the text, create frames of the same size in the other document, and paste it. But then I need to figure out a way to create threads between the two frames using the script. Im really noob in scripting, chatgpt and indesignjs.de are helping me out