Close a document immediately

Hi,
I want to close a document and reopen it immediately. I am using SDKLayoutHelper methods to open and close a document. But closing a document with kProcess always crashes. I tried various methods(IDocumentCommands, ProcessScheduledCommands) to make it work but everytime it crashes.
Can anybody suggest me what is the right way to close and reopen the document immediately?
I am using InDesign CS4.
Thanks,
VSP
P.S. I am able to close and reopen by scheduling the commands.

Hi,
I tried the following code and it crashes.I have taken the BasicMenu sample and tried to close the current active document.
As per the previous reply from Dirk I reset the docPtr before close. This is to remove the reference to the document.
Thanks,
VSP
void BscMnuActionComponent::DoAbout()
InterfacePtr<IDocument> docPtr(GetExecutionContextSession()->GetActiveContext()->GetContextDocument(), UseDefaultIID());
UIDRef documentUIDRef = ::GetUIDRef(docPtr);
InterfacePtr<IDocFileHandler> docFileHandler(Utils<IDocumentUtils>()->QueryDocFileHandler(documentUIDRef));
if (!docFileHandler)
     return;
if (docFileHandler->CanClose(documentUIDRef))
     docPtr.reset();
     docFileHandler->Close(documentUIDRef, kSuppressUI, kTrue, IDocFileHandler::kProcess); // Tried with kFullUI and it crashes.

Similar Messages

  • Re:How to close and reopen a document immediately?

    Original Message available here:<br /><a href="/webx?14@@.3c055358">Dave Sykes, "How to close and reopen a document immediately?" #, 15 Nov 2007 4:46 am</a><br /><br />> Dave Sykes - 04:46am Nov 15, 2007 Pacific<br /> I would like to close a document and then immediately afterwards open it up again.<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 />If I use IDocumentCommands::Close the close succeeds, but InDesign unexpectedly quits when it regains control.<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 />I have also tried ProcessCommand(Utils<IDocumentCommands>()->CreateCloseCommand(docUIDRef)), but this also crashes InDesign when it regains control.<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 />Is it possible to close all the layout windows and also close the document, so that it can be reopened immediately? <br /><br />I had the same issue and tried to solve it by closing all windows in the document's IWindowList and then calling IDocFileHandler::Close() with IDocFileHandler::kProcess to process the command immediately instead of scheduling it.<br />Unfortunately this still resulted in a crash.<br /><br />Eventually I got around it by adding the following line before re-opening the document:<br />CmdUtils::ProcessScheduledCmds (ICommand::kLowestPriority);<br /><br />This forced InDesign to completely close the document before re-opening it again.<br /><br />Hope this helps someone else too. :)<br /><br />- Jackeen

    I am having the same problem with InDesign CS4 version,
    I have tried the following:
    IDocFileHandler::Close() //with kSchedule command
    CmdUtils::ProcessScheduledCmds();     //Results into crash
    IWindowList::CloseAll()
    IDocFileHandler::Close() //with kSchedule command
    CmdUtils::ProcessScheduledCmds();     //Results into crash
    IDocumentList::CloseAll()
    IDocFileHandler::Close() //with kSchedule command
    CmdUtils::ProcessScheduledCmds();     //Results into crash
    IPresentationList::CloseAllPresentations()
    IDocFileHandler::Close() //with kSchedule command
    CmdUtils::ProcessScheduledCmds();     //Results into crash
    is Three anything else that could work.
    Thanks and Regards
    Saurabh Singhal

  • How to close and reopen a document immediately?

    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?

    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.

  • Used to be able to close documents immediately by clicking "X" at upper right of screen or right-clicking tab at bottom of screen. Now "X" is very slow to close. Help?

    I "upgraded" to Beta 4 but it created too many aberrations, so I went back to 3.6.15. Formerly, when I clicked on the "X" to get out of screens, it would happen imm3ediately. Now it takes several seconds. But when I right-click on the bar at the bottom of the screen, it closes that page immediately. Is this the way it's supposed to work? Thanks.

    If you are getting Siri when you double tap, then your home button must be sticking. Siri comes up when you hold the home button. Try tapping quickly twice. When that happens, the multi-tasking list comes up and you will see the app icon and then a thumbnail, or reduced size view of the app above it. You put your finger on that thumbnail and swipe upwards with your finger.
    For that issue, you might want to do a reset of the phone. Hold the sleep/wake and home buttons together until you see the Apple logo and then release. The phone will reboot. This will not affect your data.
    To be honest, your novel is a little difficult to read, and I think you put too much information in there, and a lot of it is unnecessary. Be to the point and just add information necessary to understand the issue.

  • When I open a folder then open a document in the folder every time i close the document it closes the folder where is the back button ?

    When I open a folder on my mac pro retina osx 10.9.1 then a document every time I close the document it closes the folder where is the back button?

    Try COMMAND-[.
    Ciao.

  • I can't seem to "close" my documents on MSoft Word with AppleScript!

    Hi
    I have tons of documents open on MSoft Word and wish to close some of them. Luckily, those that I wish to close all start with the word "book", so I was thinking I could actually automate that with AppleScript hence avoid closing them one by one.
    I wrote the following code:
    tell application "Microsoft Word"
    count (document)
              set countresult to result
              repeat with incrementValue from 1 to countresult
                        if name of document incrementValue starts with "book" then
      activate document
      close document
                        end if
              end repeat
    end tell
    To my surprise, it didn't work!
    I got the following under "Replies", which showed that AppleScript did indeed try to close the document that starts with "book":
    tell application "Microsoft Word"
    count every document of current application
      --> 6
    get name of document 1
      --> "book_mac_OS_X_and_iOS_internals.htm"
    activate
    close document
    get name of document 2
      --> "applicable books.htm"
    get name of document 3
      --> "What Do You Want Homespace to Do.htm"
    get name of document 4
      --> "URL_repository_for_outcomes.htm"
    get name of document 5
      --> "SYNTHESIS - History a Step Back.docx"
    get name of document 6
      --> "SYNTHESIS - History a Step Back.docx"
    end tell
    But when I went back to Word, I still saw the document there!
    I actually added an additional line (I didn't include the code in that which I pasted here) asking to count the number of documents in Word AFTER the so-called "close", and the number remains 6.
    Can anyone enlighten me on this?
    Regards,
    junxiang99

    Hi,
    The quickest way to do this (tested with OS 10.8.2, MS Word 2011) is in one line:
    tell application "Microsoft Word" to close every document whose name begins with "book"
    The reason why your script doesn't work is that you aren't specifying to Word which document you want it to close.
    So, changing one line ought to do it:
    close document incrementvalue -- instead of "close document"
    But... when you close a document, you change the document count. Document 2 becomes document 1, document 3 becomes document 2 etc. So eventually you'd get a message saying "The object you are trying to access doesn't exist".
    Because of this, if you want to do it in a repeat loop, you have to work backwards:
    tell application "Microsoft Word"
      set doc_count to count documents
      repeat with x from doc_count to 1 by -1
      if name of document x begins with "book" then close document x
      end repeat
    end tell
    Hope this helps.

  • Can't close Word document from dock

    I've never tried this before until now. I minimized several Word documents which places each one of them in the dock. When I select each document in the dock, "Close" is an option that appears, but when I select "Close", nothing happens. To close the document, I must click the document to open the window and then close the document.
    Why won't the document close as the command would imply?

    Hi Fred,
    As I said, when the Application Word is launch from the Application ore directly from one of the Word documents that I keep in the Dock for direct access, the only option I have is "Show in Finder".
    I just checked out, that it makes no differences when Word Application is already launch ore still close, there is only one option.
    * By single clicking on the Word document I can open the Application Word.
    * No more nor less.
    For closing a active Word document you can use "command-W"
    Dimaxum

  • How can I close a document without saving changes?

    I'm using Pages 4.3 with OS10.9.1.
    Before I upgraded to OS10.9.1, when I closed a document (Command W) it asked me first if I want to save the changes I'd made to the document. I had the option of saving or not saving.
    Sometimes I want to close a document without saving the changes, for example if I edit a text, then decide I prefer the unedited version.
    But now that I'm using OS10.9.1, when I close a document, it automatically saves any changes I've made.
    How can I get back to the original option of saving or not saving changes when I close a document? This option was available with the same version of Pages, when used with an earlier OS.
    I've searched the Pages Users Guide, but can't find any answer, or default settings. Pages Preferences doesn't seem to address this.
    I'm not using track changes, so I don't think that's the problem.
    Any solutions would be greatly appreciated!

    [Viking: I am using v4.3. ... See my orginal post.]
    But I found the solution, for anyone else who is having the same problem....
    Open your computer's System Preferences > General, and click the box "Ask to keep changes when closing documents."
    Now, when you close a document in Pages, a window will open giving you the option of saving changes or not.
    (I don't know whether this works in Pagesv.5., buty it works with v.4.3)

  • Pages 5 crashing every time I close a document

    Everytime I try to close a document now Pages is crashing. It will hang (the spinwheel) and the only way to close the program out is to do a force quit. Any idea on how to fix this?
    Jason

    Not when you tell us so little about what you are using and doing.
    What version of Pages?
    Anything particular about this document that we should know?
    Is this the only document causing this?
    Where are you saving it to?
    Have you tried saving it elsewhere?
    Peter

  • I am using word 11 and cannot save or close my document nor do I even have the option to edit my document

    I drafted my document without a problem. I went to do a final save and close the document but it seems as if the document is frozen. I have never experienced this before. Help! I need to print the document but I can't even do that.

    Questions about Microsoft Word are best asked on Microsoft's own forums.

  • Acrobat 8 Professional "has stopped working" every time I close a document.

    Some time ago I had a virus infection but was able to clean my computer. Before that date, Adobe Acrobat 8 Professional was working fine but since then, every time I close a document, the program closes down with the message "Acrobat 8 has stopped working". Windows will look for a solution and never finds one.
    Probably, with the virus, one of the Acrobat 8 files must have been corrupted, but I have not been able to find out which one or how to repair it.
    Anyone with a similar situation who can point me to the solution?
    Or should I just reinstall Acrobat from scratch?
    Thanks, Hubert

    Thanks, Bill,
    Tried this but my Help does not open/show the option Repair.
    Online support goes to an error page...
    Do you have/are there other repair options?
    Thanks.

  • [CS5] Unable to save or close a document

    I'm working on porting a plugin from CS4 to CS5. One of its functions is to save each page of a document as a separate file. It does this by saving a copy of the main document, opening it, removing the unwanted pages, and finally saving it. This worked fine in all previous InDesign versions, but in CS5 IDocFileHander is returning false for CanSave() and CanClose(). Ignoring that, or processing a save or close command directly, causes ID to enter protective shutdown.
    There was another message posted recently with a similar problem  ( http://forums.adobe.com/thread/647045?tstart=0 ), but I'm not performing my actions as part of a command or a command sequence. Is there another reason why InDesign wouldn't allow me to save or close a document?

    Hello Andrew,
    here is Adam from the thread you already read. I might some more hints for you. First, when I was saving my document, I needed to add a textframe, then export the document *with* the textframe to XML and after that I deleted the textframe so the user doest see anything. So it looked like:
    SaveMyDoc(docref)
         1. add a textframe
         2. export my XML file
         3. delete my textframe
         4. call IDocFileHandler to save it <- here CanSaveAs Asserted
    When I changed to following style, I got what I needed without the Assert
    SaveMyDoc(docref)
         1. call IDocFileHandler to save it
         2. add a textframe
         3. export my XML file
         4. delete the textframe
    I got no assert, but the document was dirty and the user had to do Save again which was not nice.
    I added line 5:
         call IDocFileHandler to revert to the saved file.
    Now it feels OK.
    More notes: my methods are in a facade in the model plugin and are called via Utils<IIMyUtils>(). I double checked my commands which set the persistent data in my document.
    Lets hope what is written here is useful.
    //Adam

  • Hoe do i close a document in adobe reader touch?

    I have swiped everywhere on the screen with no luck of the 'bar' at the bottom when i went through the learning. I have yet to find a way to close the document and even when i go back to the start screen or the app list all touching of the icon just brings back the app i can't get rid of. i cannot get to help or a ything but this document. i am so frustrated i just want to sceam and uninstall the app and say to h___ with adobe. Help me PLEASE!

    There are 2 or 3 ways to close a document.
    1. If you are looking at a PDF file in Adobe Reader Touch, you can bring up the app bar by swiping from the top edge of the screen downwards (you can also get the same app bar by swiping from the bottom edge of the screen upwards). The app bar should then appear and you can click or tap the "back" button in the upper left of the screen.
    2. Use the CTRL+W keyboard shortcut combination. (Hold CTRL, then press W).
    3. If you are using a mouse, it may have a Back button built into the mouse. This is usually on the left side of the mouse where your thumb rests if you're holding it with your right hand. That Back button is often configured to invoke the Back button described in scenario 1 above.

  • Trying to close a document line but exception is thrown

    I'm trying to close a document line, that is, setting LineStatus property to 1 (wich coresponds to 'C' [closed]).
    But i receive this message from SAP: 'can't close a row of this document type' (it's a translation so the message could be slightly different), prompting that this is an error in LineStatus property.
    Any ideas?
    regards
    Edited by: Peter Petrelli on Nov 12, 2008 4:32 PM

    Hi Peter,
    The first thing to test would be if you can close the line manually in the SAP Business One application without using the AddOn.
    - If not and you get the same error it might be system behaviour depending on which form.
    - If yes, there might be a bug in the DI API which should be reported in a SAP Ticket.
    The second thing to test would be if you can close the row
    - in a different document of the same type
    - in the same document type in a different database
    Let us know of your results and more specific information which document you are using.
    Kind Regards,
    Friederike
    SAP Business One Forums Team

  • [Ann] Script to Open/Close Book Documents

    .. Is this finally possible in InDesign CS6? (Along with Browse By Table and Find Backwards...)
    If not, or it is but you are still on CS4 (as I am -- I didn't test on CS5, *way* too busy for that!), download the script "bookopenall.jsx" from
    http://www.jongware.com/binaries/bookopenall.zip
    and place it inside a folder named "Startup Scripts", which you should create at the same level as the "Scripts Panel" folder (which is where your own scripts are). Restart InDesign, open a book, and you'll find two new commands in the Book Panel menu:
    "Open Book Documents" will open all of the book's documents;
    "Close Book Documents" will... close all of the book's documents! (And prompt you when changed.)
    Useful? I should think so!
    (Based heavily -- well, almost totally -- on Marc Autret's "FileCloseAll": http://www.indiscripts.com/post/2010/02/how-to-create-your-own-indesign-menus)
    Message was edited by: [Jongware]
    Title changed, as this sounded like a request. (Which it is, but it solves it right away as well.)

    Fred, I'm on both -- but usually on Windows! Don't you just *hate* that workaround? First I have to select the top document, then scroll down the list and select the bottom one. One click too many and the list is de-selected, and you end up getting just one document opened. Annoying!
    Besides, the same trick does not work for closing all book documents, does it?

Maybe you are looking for