Skip to main content
Known Participant
April 5, 2010
Question

Close a document immediately

  • April 5, 2010
  • 2 replies
  • 725 views

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.

This topic has been closed for replies.

2 replies

April 6, 2010

Try this...

InterfacePtr<IDocumentUtils> pDocUtil(GetExecutionContextSession(), IID_IDOCUMENTUTILS);

if (!pDocUtil)

     return;

// m_uidRefDoc is the UIDRef of the document you want to close

InterfacePtr<IDocFileHandler> pDocFileHandler(pDocUtil->QueryDocFileHandler(m_uidRefDoc));

if (!pDocFileHandler|| !pDocFileHandler->CanClose(m_uidRefDoc))

     return;

pDocFileHandler->Close(m_uidRefDoc, kSuppressUI);

new_beAuthor
Known Participant
April 7, 2010

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.

}

}

Legend
April 5, 2010

Make sure no InterfacePtr is referring to the document any more.

Dirk