//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(“
调用LISP失败,请检查依赖的LISP是否加载”));
acutRelRb(ptList);
return;
}
acutRelRb(ptList);
if(ptResult==NULL)
{
acutPrintf(_T(“
调用LISP失败,返回空值”));
return;
}
if(ptResult->restype!=RTSTR)
{
acutPrintf(_T(“
调用LISP失败,返回错误的值类型”));
acutRelRb(ptResult);
return;
}
CString strRC=ptResult->resval.rstring;
acutRelRb(ptResult);
acutPrintf(_T(“
返回值:%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))
)