Skip to main content
November 15, 2007
Question

How to close and reopen a document immediately?

  • November 15, 2007
  • 4 replies
  • 764 views
I would like to close a document and then immediately afterwards open it up again.<br /><br />The documentation says "To process a command to close the document immediately, use IDocumentCommands::Close'', but it also points to SDKLayoutHelper::CloseDocument which uses IDocFileHandler::Close.<br /><br />If I use IDocumentCommands::Close the close succeeds, but InDesign unexpectedly quits when it regains control.<br /><br />If I use IDocFileHandler::Close then when I reopen the document I get the assert ``Calling SelectionExtentionRegistry::Initialize more than once!'' This is the same error I get by not closing the document at all.<br /><br />I have also tried ProcessCommand(Utils<IDocumentCommands>()->CreateCloseCommand(docUIDRef)), but this also crashes InDesign when it regains control. <br /><br />In all cases I am calling ProcessCommand(CmdUtils::CreateCommand(kCloseLayoutWinCmdBoss), as otherwise I get an error that the document is still referenced on close.<br /><br />Is it possible to close all the layout windows and also close the document, so that it can be reopened immediately?
This topic has been closed for replies.

4 replies

Another_Andrew
Inspiring
July 15, 2010

Closing then opening a document can be tricky, especially if you are trying to save its contents first.

If you try to save a file and then close it with a ProcessCmd then you'll have problems

as the save cmd won't have time to complete before it is hit with the close cmd.

You can save a document and then immediately request to close it with ScheduleCmd as this

just queues the close request and will process it once the save has completed - this is okay.

But you can't then just fire a request off to reopen the document as the previous commands

are still being processed - this would be a problem.

If you try to speed the process up by using ProcessScheduledCmds then you're

basically doing a save and close with ProcessCmd and will probably have the same problems.

The issue is that you need to leave InDesign alone while it finishes saving and empties its cmd queues.

You'll probably need an asynchronous approach.

Do a save on your document data - this lets you close it - but test if you need to save first.

Do a ScheduleCmd to queue a request to close the document.

Logic should now switch to the document observer.

When you get the message that your document is closed _then_ fire the logic to open it.

July 14, 2010

More specifically: Add the following line before re-opening the document:

CmdUtils::ProcessScheduledCmds (ICommand::kLowestPriority);

(from http://www.mombu.com/computer_design/indesign/t-how-to-close-and-reopen-a-document-immediately-1705855-last.html)

May 18, 2010

CmdUtils::ProcessScheduledCmds () is another option to try

November 20, 2007
Hi,

I believe you should save the document before closing. I have used

CreateSaveCommand of IDocumentCommands to save document, previous saved with SaveAsDocument.
After that I used CreateCloseCommand.
The document was successfully closed.

Rajani Sohoni