找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 763|回复: 3

[教学]:替换ACAD内部命令的ARX方法...

[复制链接]

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-2-2 01:35:14 | 显示全部楼层 |阅读模式

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

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

×

  1. Replacing Acad's Internal Commands  
  2. ID    1957  
  3. Applies to:    AutoCAD
  4. AutoCAD 2000I
  5. AutoCAD R14

  6. Date    12/24/2001  

  7. This document is part of    AcEd     


  8. Question
  9. How do I define my own commands that replace AutoCAD's ?
  10. Answer
  11. The ObjectARX API doesn't provide an ARX method to override an AutoCAD internal
  12. command. This can only be achieved by using the "UNDEFINE" command. In the following
  13. sample, undocumented function acedPostCommand() is used to post a lisp expression
  14. that uses the UNDEFINE command to undefine the "OPEN" and "SAVEAS" command.
  15. Also, ObjectARX does provide two functions to undefine certain type of commands,
  16. they are:

  17. 1)  acedUndef()
  18. Undefines a function (an AutoLISP external function) that was previously defined
  19. by a call to acedDefun().

  20. 2) acedCmdUndefine().
  21. acedCmdUndefine only works with ARX registered commands.

  22. For example, if you want to override OPEN and SAVEAS commands, you need to do
  23. the following:


  24. // declare the following function
  25. int acedPostCommand(const char*);


  26. // place the following lines in acrxEntryPoint()'s case AcRx::kInitAppMsg:
  27.   case AcRx::kInitAppMsg:
  28.   acedPostCommand("(command "_undefine" "_open") ");   
  29.   acedPostCommand("(command "_undefine" "_saveas") ");   


  30. // ** do this always **
  31.   acedRegCmds->addCommand("MYCOMMAND_GRP", "OPEN", "_OPEN", ACRX_CMD_MODAL, rx_open);
  32.   acedRegCmds->addCommand("MYCOMMAND_GRP", "SAVE", "_SAVE",  ACRX_CMD_MODAL, rx_saveAs);
  33.   acedRegCmds->addCommand("MYCOMMAND_GRP", "SAVEAS", "_SAVEAS", ACRX_CMD_MODAL, rx_saveAs);





  34. #include <afxdlgs.h>
  35. void rx_open()
  36. {
  37.   CFileDialog FDialog (TRUE, "dwg", "",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("AutoCAD Drawing Files (*.dwg)|*.dwg||"));
  38.   
  39.   if (FDialog.DoModal() == IDOK)
  40.   {
  41.    char* pFile = new char[512];
  42.    strcpy(pFile, FDialog.GetPathName());
  43.    if(acedSyncFileOpen(pFile) != Acad::eOk)
  44.     acutPrintf("\nError open drawing file.");
  45.    delete [] pFile;
  46.   }
  47. }


  48. void rx_saveAs()
  49. {
  50.   CFileDialog FDialog (FALSE, "dwg", "",  
  51.    OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
  52.    _T("Save AutoCAD Drawing File As (*.dwg)|*.dwg||"));
  53.   
  54.   if (FDialog.DoModal() == IDOK)
  55.   {
  56.    char* pFile = new char[512];
  57.    strcpy(pFile, FDialog.GetPathName());
  58.    // user can obtain the database object through readDwgFile()
  59.    // for an external database
  60.    AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
  61.    if(pDb->saveAs(pFile) != Acad::eOk)
  62.     acutPrintf("\nError saving drawing file.");

  63.    //clean up
  64.    delete [] pFile;
  65.   }


  66. }


  67. Note:

  68. 1) You can always use the original native ACAD command by prefixing the command
  69. name with a "." even if it is already undefined.
  70. 2) The above code runs only in SDI mode due to the use of acedSyncFileOpen() method.

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2002-2-3 12:32:56 | 显示全部楼层
替换后如果能在一定的条件下也能再调用原有命令就好了,比如说有一个开关,开就调用原有的open,闭就调用我自己的open
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

使用道具 举报

发表于 2005-8-10 14:54:33 | 显示全部楼层
这个方法显然没用,只不过调用了一下AutoCAD本身的命令,稍微懂点的人来个redefine就破了!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-22 20:34 , Processed in 0.338982 second(s), 35 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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