- UID
- 675574
- 积分
- 450
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2013-5-4
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
一直以来都是使用LISP编写一些简单的程序自用,但发现LISP的SSGET用得实在太不爽了,不能自定提示和关键字。期间也试过用LISP来模仿但都达不到自己想要的效果,而是学习ARX,但发现C++学起来实在太难了,还好来到这个论坛,找到很多例子,特别是高飞大哥的源码,而是照葫芦画瓢终于写好了,帖出来希望大家能指正下。
[pcode=cpp,true]static int StampingDieSSGet(struct resbuf *rb);
static int StampingDieSSFree(struct resbuf *rb);
resbuf* ssCallback(const TCHAR* kword);
static bool Getlispresbuf(struct resbuf *lisprb,struct resbuf **rb);
TCHAR *PfunctionName;
const TCHAR *outkword;
static bool Getlispresbuf(struct resbuf *lisprb,struct resbuf **rb)
{
if (lisprb->restype != RTLB)
{
return false;
}
lisprb = lisprb->rbnext;
struct resbuf *rb1 =NULL;
struct resbuf *rb2 = NULL;
do
{
struct resbuf *temrb = acutNewRb(abs(lisprb->restype));
temrb->restype = lisprb->restype;
temrb->resval = lisprb->resval;
if (rb1 == NULL)
{
rb1 = rb2 = temrb;
}
else
{
rb2->rbnext = temrb;
rb2 = rb2->rbnext;
}
lisprb = lisprb->rbnext;
} while (lisprb != NULL && lisprb->restype != RTLE);
*rb = rb1;
return true;
}
resbuf* ssCallback(const TCHAR* kword)
{
resbuf *result = NULL;
resbuf *rb_in = NULL;
outkword = kword;
if(PfunctionName != NULL)
{
rb_in = acutBuildList(RTSTR,PfunctionName,RTSTR,kword,RTNONE);
int ret = acedInvoke(rb_in,&result);
}
else
{
throw kword;
}
return result;
}
static int StampingDieSSGet(struct resbuf *rb)
{
resbuf* (*oldFunc)(const ACHAR*);
acedSSGetKwordCallbackPtr(&oldFunc);
outkword = NULL;
PfunctionName = NULL;
TCHAR *promptStr=NULL;
ACHAR *kwordStr=NULL;
struct resbuf *filterrb = NULL;
//不带参数运行提示字符串
if(rb == NULL)
{
promptStr = _T("选择对象: ");
goto StartSSget;
}
//提示字符串
if(rb->restype == RTSTR)
{
promptStr = rb->resval.rstring;
}
else if(rb->restype == RTLB)
{
promptStr = _T("选择对象: ");
Getlispresbuf(rb,&filterrb);
goto StartSSget;
}
else
{
acutPrintf(_T("\n错误: 参数错误"));
return RTERROR;
}
rb = rb->rbnext;
if(rb == NULL)
{
goto StartSSget;
}
//关键字
if (rb->restype == RTSTR)
{
kwordStr = rb->resval.rstring;
rb = rb->rbnext;
if(rb == NULL)
{
goto StartSSget;
}
//回调函数
if(rb->restype == RTSTR)
{
PfunctionName = rb->resval.rstring;
rb = rb->rbnext;
if(rb == NULL)
{
goto StartSSget;
}
//过虑表
else if (rb->restype == RTLB)
{
Getlispresbuf(rb,&filterrb);
}
else
{
acutPrintf(_T("\n错误: 第四个参数过虑表"));
return RTERROR;
}
}
//过虑表
else if(rb->restype == RTLB)
{
Getlispresbuf(rb,&filterrb);
goto StartSSget;
}
else
{
acutPrintf(_T("\n错误: 第三个参数为回调函数字符串或过虑表"));
return RTERROR;
}
}
//过虑表
else if(rb->restype == RTLB)
{
Getlispresbuf(rb,&filterrb);
goto StartSSget;
}
else
{
acutPrintf(_T("\n错误: 第二参数为关键字或过虑表"));
return RTERROR;
}
StartSSget:
TCHAR *prorptlist[] = {promptStr,_T("删除对象: ")};
ads_name ss;
try
{
if(kwordStr != NULL)
{
acedSSSetKwordCallbackPtr(ssCallback);
if (RTNORM == acedSSGet(_T("_:$:K"),prorptlist,kwordStr,filterrb,ss))
{
acedRetName(ss,RTPICKS);
//acedSSFree(ss);
}
}
else
{
if (RTNORM == acedSSGet(_T("_:$"),prorptlist,NULL,filterrb,ss))
{
acedRetName(ss,RTPICKS);
//acedSSFree(ss);
}
}
acedSSSetKwordCallbackPtr(*oldFunc);
}
catch(...)
{
if(outkword != NULL)
{
acedRetStr(outkword);
}
else
{
acedRetNil();
}
acedSSFree(ss);
acedSSSetKwordCallbackPtr(*oldFunc);
}
return 0;
};
static int StampingDieSSFree(struct resbuf *rb)
{
if(rb == NULL)
{
acutPrintf(_T("\n错误: 参数为空"));
return RTERROR;
}
if(rb->restype != RTPICKS)
{
acutPrintf(_T("\n错误: 参数类型错误."));
return RTERROR;
}
ads_name ss ;
ads_name_set(rb->resval.rlname,ss);
acedSSFree(ss);
acedRetT();
return RTNORM;
};[/pcode]
|
评分
-
查看全部评分
|