最初由 wweien 发布
[B]看了你的例子,谢谢。
你的例子中创建新文档主要是:
AcApDocument* pDoc = acDocManager->curDocument();
//create the new doc
acDocManager->appContextNewDocument("acad.dwt");
//get a pointer to ... [/B]
看看下面的资料,你就应该明白为什么要使用模板图(DWT)了,你可以把你的图形保存后,改扩展名为DWT,并且讲解了为什么要LOCK文档和如何使用定义命令标记,都是由原因的。

- [FONT=courier new]
- How to create a copy of the current document into a new document?
- ID 53139
- Applies to: AutoCAD 2000
-
-
- This document is part of AcDbDatabase ObjectARX Opening Drawings Wblock
- Question
- How can I have an identical copy of the current document and create it as a new
- document?
- Answer
- There are two solutions to this problem.
- One solution is detaled in DevNote #50697.
- Another solution is create a temporary drawing template file from the current
- database first, then create a new drawing with the template. Then delete it if
- necessary. Here is an outline of required steps followed by a code fragment.
- 1. Wblock the current open drawing.
- 2. Save the wblocked drawing as a template file (with a DWT extension) to a
- temporary location on your hard drive.
- 3. From the application context create a NEW document using the previously saved
- template file.
- 4. If necessary, 'remove' the temporary template file from your hard drive.
- Code fragment:
- void newDocHelper(void *pData);
- // Please note, here we are using "C:/temp.dwt" as a location
- // for our temporary template file. Please change this location
- // to suit your requirements as appropriate.
- void copydwg()
- {
- // TODO: Implement the command
- AcDbDatabase *pDb = NULL;
- AcDbDatabase *pnewDb = NULL;
- pDb = acdbHostApplicationServices()->workingDatabase();
- assert( pDb != NULL );
- if( pDb->wblock(pnewDb) != Acad::eOk ) {
- acutPrintf("Couldn't wblock.\n");
- return;
- }
-
- if( pnewDb->saveAs("C:/temp.dwt") != Acad::eOk) {
- acutPrintf("Couldn't saveAs C:/temp.dwt file.\n");
- delete pnewDb;
- return;
- }
- delete pnewDb;
- static char pData[] = "c:/temp.dwt";
- acDocManager->executeInApplicationContext(newDocHelper, (void *)pData);
- // 'remove' is a C function to delete a file and its syntax is int remove(
- const char *path );
- remove("c:/temp.dwt");
- }
- void newDocHelper(void *pData)
- {
- AcApDocument* pDoc = acDocManager->curDocument();
- if (acDocManager->isApplicationContext())
- {
- acDocManager->appContextNewDocument((const char *)pData);
- }
- else
- {
- acutPrintf("\nERROR: in Document context : %s\n",pDoc->fileName());
- }
- }
- NOTE: Do not register this command with flag 'ACRX_CMD_SESSION' because
- AcDbDatabase::wblock() will fail in this context. As for how to execute a NEW or
- OPEN functionality in an ARX command running either in application context or
- document context, refer to DevNote #32094.
- [/FONT]
|