找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 2745|回复: 17

[求助]:请教怎样在cad2000中实现多文档的自动转换?

[复制链接]
发表于 2002-10-12 13:44:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
请教一下各位大侠?怎样实现多文旦转换,就可以在编程时自动的转换,比如把一个程序中的两个图形保存为不同的文件名,并且,可以在cad2000内同时打开?请给我一个实例!不胜感谢!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-10-12 14:09:04 | 显示全部楼层

Re: [求助]:请教怎样在cad2000中实现多文档的自动转换?

最初由 wweien 发布
[B]请教一下各位大侠?怎样实现多文旦转换,就可以在编程时自动的转换,比如把一个程序中的两个图形保存为不同的文件名,并且,可以在cad2000内同时打开?请给我一个实例!不胜感谢! [/B]


问题我想可以归结为一个,就是如何创建一个新文档,然后打开它。

给你贴篇资料:

Method #1
Register your command with ACRX_CMD_SESSION flag and use the
appContextNewDocument API to create the new document. The drawback of this
approach is that your command will be executed in the application context,
therefore, you will need to do explicit document locking if you want to interact
with any documents. Also, you cannot use acedCommand/acedCmd/acedInvoke APIs
from the application context.

Method #2
Register your command with ACRX_CMD_MODAL flag and use the
executeInApplicatonContext API within your command handler to switch the
application context. The drawback of this approach is that you will need to
create a hidden window that coordinates the activation of the newly created
document once the 'creator' command finishes.

上面两个方法的实例代码都在附件中,你下载看看。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2002-10-12 14:24:57 | 显示全部楼层
我出赚点钱再来,哈哈
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-10-12 14:28:38 | 显示全部楼层
最初由 wweien 发布
[B]我出赚点钱再来,哈哈 [/B]


多参与ARX帖子的讨论吧,开发论坛不应该灌水,你说呢:)
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2002-10-12 14:46:00 | 显示全部楼层
多谢xdsoft,我下载了,thank you very much!!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2002-10-12 15:12:58 | 显示全部楼层
看了你的例子,谢谢。
你的例子中创建新文档主要是:
AcApDocument* pDoc = acDocManager->curDocument();
        //create the new doc
    acDocManager->appContextNewDocument("acad.dwt");
        //get a pointer to it
        *((AcApDocument**)pData) = acDocManager->curDocument();
        //go back to the original doc to finish the command there
        acDocManager->activateDocument(pDoc);       
acDocManager->appContextNewDocument("acad.dwt");
但是我看一本书上的关于多文档的很多是数据库的东西。还重载了文档管理反应器类。AcDbDatabaseReactor。我只需要在程序中能够打开另一个文档而以需要重载吗?这一块我看不太明白,请指教!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-10-12 15:24:10 | 显示全部楼层
最初由 wweien 发布
[B]看了你的例子,谢谢。
你的例子中创建新文档主要是:
AcApDocument* pDoc = acDocManager->curDocument();
        //create the new doc
    acDocManager->appContextNewDocument("acad.dwt");
        //get a pointer to ... [/B]


看看下面的资料,你就应该明白为什么要使用模板图(DWT)了,你可以把你的图形保存后,改扩展名为DWT,并且讲解了为什么要LOCK文档和如何使用定义命令标记,都是由原因的。


  1. [FONT=courier new]
  2. How to create a copy of the current document into a new document?  
  3. ID    53139  
  4. Applies to:    AutoCAD 2000


  5. This document is part of    AcDbDatabase   ObjectARX   Opening Drawings   Wblock     


  6. Question
  7. How can I have an identical copy of the current document and create it as a new
  8. document?
  9. Answer
  10. There are two solutions to this problem.

  11. One solution is detaled in DevNote #50697.

  12. Another solution is create a temporary drawing template file from the current
  13. database first, then create a new drawing with the template. Then delete it if
  14. necessary. Here is an outline of required steps followed by a code fragment.

  15. 1.  Wblock the current open drawing.
  16. 2.  Save the wblocked drawing as a template file (with a DWT extension) to a
  17. temporary location on your hard drive.
  18. 3. From the application context create a NEW document using the previously saved
  19. template file.
  20. 4. If necessary, 'remove' the temporary template file from your hard drive.

  21. Code fragment:
  22. void newDocHelper(void *pData);

  23. // Please note, here we are using "C:/temp.dwt" as a location
  24. // for our temporary template file. Please change this location
  25. // to suit your requirements as appropriate.
  26. void copydwg()
  27. {
  28.    // TODO: Implement the command
  29.    AcDbDatabase *pDb = NULL;
  30.    AcDbDatabase *pnewDb = NULL;

  31.    pDb = acdbHostApplicationServices()->workingDatabase();
  32.    assert( pDb != NULL );

  33.    if( pDb->wblock(pnewDb) != Acad::eOk ) {
  34.         acutPrintf("Couldn't wblock.\n");
  35.         return;
  36.    }
  37.    
  38.    if( pnewDb->saveAs("C:/temp.dwt") != Acad::eOk) {
  39.         acutPrintf("Couldn't saveAs C:/temp.dwt file.\n");
  40.         delete pnewDb;
  41.         return;
  42.    }

  43.    delete pnewDb;

  44.    static char pData[] = "c:/temp.dwt";
  45.    acDocManager->executeInApplicationContext(newDocHelper, (void *)pData);

  46.    // 'remove' is a C function to delete a file and its syntax is int remove(
  47. const char *path );
  48.    remove("c:/temp.dwt");
  49. }

  50. void newDocHelper(void *pData)
  51. {
  52.    AcApDocument* pDoc = acDocManager->curDocument();
  53.    if (acDocManager->isApplicationContext())
  54.    {
  55.         acDocManager->appContextNewDocument((const char *)pData);
  56.    }
  57.    else
  58.    {
  59.         acutPrintf("\nERROR: in Document context : %s\n",pDoc->fileName());
  60.    }
  61. }
  62. NOTE: Do not register this command with flag 'ACRX_CMD_SESSION' because
  63. AcDbDatabase::wblock() will fail in this context. As for how to execute a NEW or
  64. OPEN functionality in an ARX command running either in application context or
  65. document context, refer to DevNote #32094.
  66. [/FONT]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2002-10-14 17:01:04 | 显示全部楼层
i am a newer.can you tell me the means of DevNote#32094?and how can i find it?
thank you
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-10-14 17:11:16 | 显示全部楼层
最初由 wweien 发布
[B]i am a newer.can you tell me the means of DevNote#32094?and how can i find it?
thank you [/B]


那是ADN开发资料的一个文件,下面资料是在2000下定义一个等价于acedsyncfileopen 打开文件功能的命令。


  1. [FONT=courier new]
  2. What is the equivalent of acedsyncfileopen in AutoCAD 2000?  
  3. ID    32094  
  4. Applies to:    AutoCAD 2000

  5. This document is part of   ObjectARX   Opening Drawings   Saving Files   


  6. Question
  7. What is the equivalent function to acedSyncFileOpen in AutoCAD 2000?
  8. Answer
  9. The acedSyncFileOpen() function is more relevant to AutoCAD Releases 14 abd
  10. 14.01than to AutoCAD 2000. ObjectARX in AutoCAD 14 can have only one database
  11. open and be available to the AutoCAD editor.  

  12. The situation is different in AutoCAD 2000 because the program is a Multiple
  13. Document Environment. As a result, there are two ways you can open a drawing
  14. file. These two ways are:

  15. Method #1
  16. Create a command to execute in the application context by registering the
  17. command with ACRX_CMD_SESSION and calling 'appContextOpenDocument()' on the
  18. particular drawing file you want to open.

  19. Method #2
  20. Explicitly make a function execute in the application context by making a call
  21. to 'AcApDocManager::executeInApplicationContext()', then pass the address of a
  22. function that you want to execute and any optional data that the invoked
  23. function can use.

  24. NOTE: If you are unfamiliar with the term "application context",  read Chapter
  25. 16, "The Multiple Document Interface" in the ObjectARX Developers Guide for
  26. AutoCAD 2000.

  27. Consider the following:
  28. acedRegCmds->addCommand("DCG_GROUP", "OP1", "OP1", ACRX_CMD_SESSION, op1);
  29. acedRegCmds->addCommand("DCG_GROUP", "OP2", "OP2", ACRX_CMD_MODAL, op2);
  30. For the first command 'OP1' the command flag is ACRX_CMD_SESSION, which means
  31. that the command will be executed in the application context. The function that
  32. is called as a result of entering 'OP1' at the command prompt is 'op1()'. For
  33. the second command 'OP2', it is a modal command which calls the 'op2()'
  34. function. Now let's look at these functions:

  35. The following code omits error-checking and assumes the existence of these three
  36. drawing files: test1.dwg, test2.dwg, and test3.dwg.
  37. // This is command 'OP1'
  38. void op1()
  39. {
  40.         // TODO: Implement the command
  41.         Acad::ErrorStatus es;

  42.         es = acDocManager->appContextOpenDocument("test1.dwg");
  43.         es = acDocManager->appContextOpenDocument("test2.dwg");
  44. }
  45. In the preceding function 'op1()', we use 'acDocManager', which is a macro that
  46. will give us a pointer to the AcApDocManager object. We then simply call
  47. 'appContextOpenDocument()'. This works because the command that calls this
  48. function is registered with the command flag, ACRX_CMD_SESSION.

  49. In the following function, a call is made to 'executeInApplicationContext()', to
  50. which a function pointer and a data string 'pData' is passed that names the
  51. drawing to be opened.

  52. The function 'openDocHelper()' is then responsible for invoking
  53. 'appContextOpenDocument()'.
  54. // This is command 'OP2'
  55. void op2()
  56. {
  57.    // TODO: Implement the command
  58.    static char pData[] = "test3.dwg";

  59.    AcApDocument* pDoc = acDocManager->curDocument();
  60.    if (pDoc)
  61.    {
  62.         acutPrintf("\nCurrently in Document context : %s, Switching to
  63. App.\n",pDoc->fileName());
  64.         acDocManager->executeInApplicationContext(openDocHelper, (void *)pData);
  65.    }         

  66. }

  67. void openDocHelper(void *pData)
  68. {
  69.    AcApDocument* pDoc = acDocManager->curDocument();
  70.    if (acDocManager->isApplicationContext())
  71.    {
  72.         acDocManager->appContextOpenDocument((const char *)pData);
  73.    }
  74.    else
  75.    {
  76.         acutPrintf("\nERROR: in Document context : %s\n",pDoc->fileName());
  77.    }
  78. }
  79. [/FONT]
复制代码


下面附件是一个完整的工程,其中介绍了AcApDocManager 类如何使用。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2002-10-15 18:51:43 | 显示全部楼层
今天把xdsoft的44759又调试运行了一遍,终于有点懂了。
谢谢晓东。
(不过我发现的理解能力好像是太菜了点,对自己的不满程度上升10个点)
above all ,thank you , xdsoft, i benefet much from it.
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2002-12-16 16:51:11 | 显示全部楼层
如果是创建系列文档呢???
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2002-12-26 23:44:53 | 显示全部楼层
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2006-8-5 22:55:35 | 显示全部楼层
好东西, 可以侃侃
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2006-11-11 09:15:05 | 显示全部楼层
这样的资料,也只在XD这里才能找到,谢了!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2007-2-2 13:51:52 | 显示全部楼层
谢谢共享!!!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-5-29 15:28 , Processed in 0.219817 second(s), 60 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表