I do something like this in my scripts:
var win:LayoutWindow = doc.layoutWindows.item(0);
win.activePage = doc.pages.item(0); // set to view page 0
@Willy – you could identify the documents by their name property.
var doc1Name = app.documents.name; var doc2Name = app.documents.name; var doc3Name = app.documents.name;
Or you already know the names of the documents in advance…
To access the documents by name, try this:
var myFirstDoc = app.documents.itemByName("doc1Name"); var mySecondDoc = app.documents.itemByName("doc2Name"); var myThirdDoc = app.documents.itemByName("doc3Name");
This will work until you change the names…
app.activeDocument = myThirdDoc;
I managed to cycle with app.activeDocument but code who was working before I changed focus of documents does not work anymore after the change.
For instance when I want to apply a paragraph style I receive a error message telling that the object is from another document or from another workspace.
Any idea why this happens?
I think if working with properties of a different document on another document, you first have to "bring" those properties to the document you want to work with.
An example: if you want work with paragraph style "p1" in "docA" and "p1" is not defined in "docA", but is defined in "doc B", you first have to copy some text formatted with "p1" from "docB" to "docA". Or use the import function with paragraph styles…
The right paragraph styles are in the right documents.
I try to explain what I would like to do with an example.
I have 3 doc's open : docA, docB, docC. Current active document is for example docB.
In my code I start building elements in succession in docA then docB and then docC.
When I run my code without changing focus to docA with app.activeDocument everything works fine without any error but the changes in docA and docC are not showed on screen during execution.
I would like that the user can follow the changes in every doc regardless of which document is active by start.
Using app.activeDocument to change focus to docA gives the error about another document or workspace...
Is there another way to accomplish what I want?
Hm. For that I have no answer. Don't know if that is even possible, because a redraw of all changes you have made to a particular document is shown AFTER fully executing and finishing the script…
Maybe I'm wrong with that…
In my experience, what actually shows up on the screen while a script is executing is hard to predict, because InDesign's redraw routines are not under direct control of a script.
That said, I think that playing with the Layout window for each document gives you the best chance at something approximating the feedback that you want. See my suggestions previously.
My scripts and Extensions almost always work with multiple documents simultaneously, so I'm pretty familiar with what happens :-)