- UID
- 1
- 积分
- 15891
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-3
- 最后登录
- 1970-1-1
|
发表于 2002-9-23 18:52:32
|
显示全部楼层
替换ACAD的内部命令的方法
给你贴篇ADN资料,替换ACAD的内部命令的方法
- Replacing Acad's Internal Commands
- ID 1957
- Applies to: AutoCAD
- AutoCAD 2000I
- AutoCAD R14
-
- Date 12/24/2001
-
- This document is part of AcEd
- Question
- How do I define my own commands that replace AutoCAD's ?
- Answer
- The ObjectARX API doesn't provide an ARX method to override an AutoCAD internal
- command. This can only be achieved by using the "UNDEFINE" command. In the following
- sample, undocumented function acedPostCommand() is used to post a lisp expression
- that uses the UNDEFINE command to undefine the "OPEN" and "SAVEAS" command.
- Also, ObjectARX does provide two functions to undefine certain type of commands,
- they are:
- 1) acedUndef()
- Undefines a function (an AutoLISP external function) that was previously defined
- by a call to acedDefun().
- 2) acedCmdUndefine().
- acedCmdUndefine only works with ARX registered commands.
- For example, if you want to override OPEN and SAVEAS commands, you need to do
- the following:
- // declare the following function
- int acedPostCommand(const char*);
- // place the following lines in acrxEntryPoint()'s case AcRx::kInitAppMsg:
- case AcRx::kInitAppMsg:
- acedPostCommand("(command "_undefine" "_open") ");
- acedPostCommand("(command "_undefine" "_saveas") ");
- // ** do this always **
- acedRegCmds->addCommand("MYCOMMAND_GRP", "OPEN", "_OPEN", ACRX_CMD_MODAL, rx_open);
- acedRegCmds->addCommand("MYCOMMAND_GRP", "SAVE", "_SAVE", ACRX_CMD_MODAL, rx_saveAs);
- acedRegCmds->addCommand("MYCOMMAND_GRP", "SAVEAS", "_SAVEAS", ACRX_CMD_MODAL, rx_saveAs);
- #include <afxdlgs.h>
- void rx_open()
- {
- CFileDialog FDialog (TRUE, "dwg", "",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("AutoCAD Drawing Files (*.dwg)|*.dwg||"));
-
- if (FDialog.DoModal() == IDOK)
- {
- char* pFile = new char[512];
- strcpy(pFile, FDialog.GetPathName());
- if(acedSyncFileOpen(pFile) != Acad::eOk)
- acutPrintf("\nError open drawing file.");
- delete [] pFile;
- }
- }
- void rx_saveAs()
- {
- CFileDialog FDialog (FALSE, "dwg", "",
- OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- _T("Save AutoCAD Drawing File As (*.dwg)|*.dwg||"));
-
- if (FDialog.DoModal() == IDOK)
- {
- char* pFile = new char[512];
- strcpy(pFile, FDialog.GetPathName());
- // user can obtain the database object through readDwgFile()
- // for an external database
- AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
- if(pDb->saveAs(pFile) != Acad::eOk)
- acutPrintf("\nError saving drawing file.");
-
- //clean up
- delete [] pFile;
- }
- }
- Note:
- 1) You can always use the original native ACAD command by prefixing the command
- name with a "." even if it is already undefined.
- 2) The above code runs only in SDI mode due to the use of acedSyncFileOpen() method.
|
|