ObjectARX調用LISP方法(含參數傳遞)返回值
//acrxEntryPoint.cpp
void Test()
{
struct resbuf *ptList,*ptResult=NULL;
//注意,一定要寫成_T(“c:lisp_test”),寫成”c:lisp_test”調用會失敗
double dx=135.6;
double dy=147.5;
ptList=acutBuildList(RTSTR,_T(“c:lisp_test”),RTREAL,dx,RTREAL,dy,RTNONE);
int rc=acedInvoke(ptList,&ptResult);
if(rc!=RTNORM)
{
acutPrintf(_T(“\r\n調用LISP失敗,請檢查依賴的LISP是否加載”));
acutRelRb(ptList);
return;
}
acutRelRb(ptList);
if(ptResult==NULL)
{
acutPrintf(_T(“\r\n調用LISP失敗,返回空值”));
return;
}
if(ptResult->restype!=RTSTR)
{
acutPrintf(_T(“\r\n調用LISP失敗,返回錯誤的值類型”));
acutRelRb(ptResult);
return;
}
CString strRC=ptResult->resval.rstring;
acutRelRb(ptResult);
acutPrintf(_T(“\r\n返回值:%s”),strRC);
}
//—————————————————————————–
//—– ObjectARX EntryPoint
class CInvokeLispTestApp : public AcRxArxApp {
public:
CInvokeLispTestApp () : AcRxArxApp () {}
virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
// TODO: Load dependencies here
// You *must* call On_kInitAppMsg here
AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
acedRegCmds->addCommand(_T(“InvokeLispTestApp”),_T(“Test”),_T(“Test”),0,Test);
// TODO: Add your initialization code here
return (retCode) ;
}
virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
// TODO: Add your code here
// You *must* call On_kUnloadAppMsg here
AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;
// TODO: Unload dependencies here
acedRegCmds->removeGroup(_T(“InvokeLispTestApp”));
return (retCode) ;
}
virtual void RegisterServerComponents () {
}
} ;
//—————————————————————————–
IMPLEMENT_ARX_ENTRYPOINT(CInvokeLispTestApp)
//InvokeLispTest.lsp
;;定義函數lisp_test
;;函數有兩個參數x,y
;;函數名必須寫成c:xx否則ARX無法調用
(defun c:lisp_test(x y)
;;將X轉換成字符串
(setq strX(rtos x 2 10))
;;將Y轉換成字符串
(setq strY(rtos y 2 10))
;;將X,Y轉換的字符串合並起來,並返回給ARX函數
;;返回給ARX調用
;;LISP最后一個運算的返回值做為函數的返回值
(setq strXY(strcat strX “|” strY))
)