Bootstrap

给cad发送命令的五种方法

1、acedCommand()

acedCommand(RTSTR,_T("UNDO"),RTSTR,_T("M"),RTNONE);//标记;

acedCommand(RTSTR,_T("UNDO"),RTSTR,_T("B"),RTNONE);//后退;

2、sendStringToExecute()

CString strCommand;
strCommand.Format(_T("ZOOM\nw\n%lf,%lf,%lf\n%lf,%lf,%lf\n"),MinPt.x,MinPt.y,MinPt.z,MaxPt.x,MaxPt.y,MaxPt.z);
acDocManager->sendStringToExecute(acDocManager->curDocument(),strCommand,true,false,false);//使用zoom命令定位区域
//最后一个参数用来设置是否在命令行上回显

3、ads_queueexpr()

CString strCmdLoad;
//加载有组名的菜单文件
strCmdLoad.Format(_T("(if (null (menugroup \"%s\"))
(command \"menuload\" \"%s\"))"), strMenuGroup, strFilePath);
ads_queueexpr((LPTSTR)(LPCTSTR)strCmdLoad);//此函数,相当于程序结束后,给CAD发送一个加载菜单的命令

4、Windows API 方法

void SendCmdToAcad(ACHAR *cmd)
{   
    COPYDATASTRUCT cmdMsg;   
    cmdMsg.dwData = (DWORD)1;   
    cmdMsg.cbData = (DWORD)(_tcslen(cmd) + 1) * sizeof(ACHAR);        cmdMsg.lpData = cmd;   
    SendMessage(adsw_acadMainWnd(), WM_COPYDATA, NULL,(LPARAM)&cmdMsg);
}

5、Com 方法

void SendCommandTest(void)
{      
    IAcadApplicationPtr pApp = acedGetIDispatch(TRUE);
    IAcadDocumentPtr pDoc;  
    pApp->get_ActiveDocument(&pDoc);   
    pDoc->SendCommand( _T("_POINT 4,4,0 ") );
}
;