Copy link to clipboard
Copied
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."
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Which layer is active?
Can you post some screenshot(s)?
With edges visible and Layers pallet.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
If your Layer is "active" / selected on the Layers Panel:
the menu is inactive.
But if you select ITEM on the Layers Pallet:
then the menu option IS ACTIVE.
But this menu option doesn't work the way you are hoping for - it's for a situations when you select item ON the Layers pallet - and want this item to be selected IN the InDesign - it won't select all items on this Layer - in your document.
I've "selected" item on the Layers panel - but it isn't selected in the InDesign:
- and when I select this option - it will get selected.
But then "focus" switches to the parent Layer - and this menu option becomes inactive again:
Copy link to clipboard
Copied
Do you need to copy those TFs - in their currennt state - or do you need to just copy text contents?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
So you need just text contents or size and relative location of the TFs as well?
In order to select those TFs - you would have to first get parentStory of the TF, then iterate though textContainers collection of this Story and use select method - and add each of the containers to the selection:
Unfortunately, I'm on my phone right now so can't give you working code.
Copy link to clipboard
Copied
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');
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.)