The sample code closes all documents, including the current one by first closing all documents except the current one in the document context. The current document is then closed from the application context using the executeInApplicationContext API. This allows the current document to be closed from the same command which is running in the document context.
// Close the other documents
AcApDocumentIterator *Iter
= acDocManager->newAcApDocumentIterator();
while(!Iter->done())
{
if (Iter->document()!=acDocManager->curDocument())
{
acDocManager->closeDocument(Iter->document());
}
Iter->step();
}
delete Iter;
// Now close the current document
::acDocManagerPtr()->appContextCloseDocument
(acDocManager->curDocument());

Leave a Reply