// Notification when a SAVE is complete Typical method to detect when // a document has been renamed void AsdkEditorReactor::saveComplete (AcDbDatabase*, const char* pActualName) { AcApDocument* pDoc = acDocManager->curDocument(); if (pDoc) acutPrintf("DOCUMENT: Save complete %s\n", pDoc->fileName()); }
// // NAME: selectDocument // // REMARKS: Simple utility to have the user choose an open document to // perform some action on. // // // // RETURNS: // void static AcApDocument* selectDocument() { AcApDocument* documentArray[10]; AcApDocument* pDoc; AcApDocumentIterator* pDocIter; int nDocs = 0;; pDocIter = acDocManager->newAcApDocumentIterator(); for ( ; !pDocIter->done(); pDocIter->step(), nDocs++) { pDoc = pDocIter->document(); documentArray[nDocs] = pDoc; acutPrintf("%d. %s\n", nDocs + 1, pDoc->fileName()); } delete pDocIter; acedInitGet(RSG_NOZERO | RSG_NONEG, NULL); int iSelection; int inputStatus = acedGetInt("Which document should this command execute in: ", &iSelection); if (inputStatus == RTNORM && iSelection <= nDocs) { return documentArray[iSelection - 1]; } else { return NULL; } }
// NAME: newSyncDoc() // // REMARKS: Simple function which requests a NEW to be executed via the application context. // // // NOTEs: See explanation for inAppContext() // RETURNS: // void // void newSyncDoc() { static char pData[] = /*NOXLATE*/"acad.dwt"; AcApDocument* pDoc = acDocManager->curDocument(); if (pDoc) { acutPrintf("\nCurrently in Document context : %s, Switching to App.\n",pDoc->fileName()); acDocManager->executeInApplicationContext(newSyncDocHelper, (void *)pData); } }
// NAME: newSyncDocHelper() // // REMARKS: Simple callback function to be executed in the application context. // Demonstrates creating a new document synchronously to retain control // in caller function // // NOTEs: See explanation for inAppContext() // RETURNS: // void // void newSyncDocHelper( void *pData) { AcApDocument* pDoc = acDocManager->curDocument(); if (acDocManager->isApplicationContext()) { acutPrintf("\nSucessfully Switched to App. Context\n"); acDocManager->appContextNewDocument((const char *)pData); acutPrintf("\nOpened a new document synchronously.\n"); } else acutPrintf("\nERROR: in Document context : %s\n",pDoc->fileName()); }
// NAME: appcontext() // // REMARKS: Simple function which requests a routine to be executed via the application context. // // // NOTEs: See explanation for inAppContext() // RETURNS: // void // void appContext() { static char pData[] = "Test Param"; AcApDocument* pDoc = acDocManager->curDocument(); if (pDoc) { acutPrintf("\nCurrently in Document context : %s, Switching to App.\n",pDoc->fileName()); acDocManager->executeInApplicationContext(inAppContext, (void *)pData); } }
// NAME: inAppContext() // // REMARKS: Simple callback function to be executed in the application context. // // NOTES: The application context is unique from each document. It is the supervisor // that delegates between each document that is currently opened. Mode-less dialogs // and other floating dialogs execute in this domain. As such it is the only // context where a document can be created that will not be suspended when the new document // becomes active. In the previous OPEN and NEW APIs it was explained that once // suspended a line of code following those APIs would not be executed until that // document is activated again. For advanced operations a developer may require the // ability to execute a routine from within the applciation context to overcome // this limitation. As such, executeInApplicationContext() and its companion funcitons // appContextOpenDocument() and appContextNewDocument() were provided. // // // RETURNS: // void // void inAppContext( void *pData) { AcApDocument* pDoc = acDocManager->curDocument(); if (acDocManager->isApplicationContext()) { acutPrintf("\nSucessfully Switched to App. Context\n"); if (pData != NULL) acutPrintf("\nData: %s\n", (char *)pData); } else acutPrintf("\nERROR: in Document context : %s\n",pDoc->fileName()); }
// // NAME: listDocuments // // REMARKS: Iterate over all the open documents. Very common piece of code // for MDI aware applications. // // // RETURNS: // void void listDocuments() { AcApDocument* pDoc; AcApDocumentIterator* pDocIter; pDocIter = acDocManager->newAcApDocumentIterator(); for ( ; !pDocIter->done(); pDocIter->step()) { pDoc = pDocIter->document(); acutPrintf(" %s\n", pDoc->fileName()); } delete pDocIter; }
// // NAME: send // // REMARKS: Simple routine to exercise switching between documents and sending commands. // // NOTEs: The actual signature for sendStringToExecute is: // virtual Acad::ErrorStatus sendStringToExecute( // AcApDocument* pAcTargetDocument, // const char * pszExecute, // bool bActivate = true, // bool bWrapUpInactiveDoc = false) = 0; // // By default this API activates the document you are sending the string to // to be executed to. The last parameter, bWrapUpInactiveDoc is only applicable // if bActivate == False. This special ability allows you to "clean up" // a document you might have left with some dangling command when constructing // a command that spans documents. One scenario is you are in the middle of // a custom command whose implementation is designed to "follow" the user // as they move from one document to another. If you have registered a reactor // on documentToBeActivated(). When this reactor fires you wish to complete // your current command in the document that is being deactivated and start // a command in the document about to be activated. // Given these conditions, you would possibly send a "return" to the old // document and "execute my new command" string to the one about to activated. // The "return" you would want to process in the background so you would pass // bActivate = False and bWrapUpInactiveDoc = True. // // RETURNS: // void // void send() { AcApDocument* pDoc = selectDocument(); if (pDoc == NULL) { acutPrintf("No document selected.\n"); return; } acDocManager->sendStringToExecute(pDoc, /*NOXLATE*/"_Line\n"); // The API inputPending() allows you to check to see if someone else has already // made a request via sendStringToExecute() to a target document. // You may not care if your command is autonomous and does not depend on the target // document being in a quiescent state. If not call both isQuiescent() and inputPending() acutPrintf("\nSent String to Doc: %s Pending Input %d\n", pDoc->fileName(), acDocManager->inputPending(pDoc)); }