求助:自定义函数如何返回选择集
本帖最后由 Lisper 于 2013-8-14 11:50 编辑求助高手:
用arx自定义了一个函数,提供给Lisp调用,功能是连续绘制几条直线,然后将绘制的所有直线作为选择集传递给lisp作为返回值,请高手给下面的代码修改一下供学习!
谢谢!
下面是我的代码,但返回值不对:
static int ads_line1(void)
{
struct resbuf *pArgs =acedGetArgs () ;
//判断第一点
AcGePoint3d p1;
if (pArgs == NULL)
{
acdbFail(_T("\n参数错误"));
return RTERROR;
}
if (pArgs->restype == RTPOINT)
{
AcGePoint2d p;
p = asPnt2d(pArgs->resval.rpoint);
p1.set(p.x,p.y,0.0);
pArgs = pArgs->rbnext;
}
else if (pArgs->restype == RT3DPOINT)
{
p1 = asPnt3d(pArgs->resval.rpoint);
pArgs = pArgs->rbnext;
}
else
{
acdbFail(_T("\n参数错误"));
return RTERROR;
}
//判断第二点
AcGePoint3d p2;
if (pArgs == NULL)
{
acdbFail(_T("\n参数错误"));
return RTERROR;
}
if (pArgs->restype == RTPOINT)
{
AcGePoint2d p;
p = asPnt2d(pArgs->resval.rpoint);
p2.set(p.x,p.y,0.0);
pArgs = pArgs->rbnext;
}
else if (pArgs->restype == RT3DPOINT)
{
p2 = asPnt3d(pArgs->resval.rpoint);
pArgs = pArgs->rbnext;
}
else
{
acdbFail(_T("\n参数错误1"));
return RTERROR;
}
AcDbEntity *pEnt;
ads_name ent,ss,resSS;
AcDbObjectId IdLine;
IdLine = CCreateEnt::CreateLine(p1,p2);
acdbGetAdsName(ent,IdLine);
p1 = p2;
while (pArgs != NULL)
{
if (pArgs->restype == RTPOINT)
{
AcGePoint2d p;
p = asPnt2d(pArgs->resval.rpoint);
p2.set(p.x,p.y,0.0);
pArgs = pArgs->rbnext;
}
else if (pArgs->restype == RT3DPOINT)
{
p2 = asPnt3d(pArgs->resval.rpoint);
pArgs = pArgs->rbnext;
}
else
{
acdbFail(_T("\n参数错误1"));
return RTERROR;
}
IdLine = CCreateEnt::CreateLine(p1,p2);
acdbGetAdsName(ent,IdLine);
acedSSAdd(ent,ss,resSS);
ads_name_set(resSS,ss);
p1 = p2;
}
//返回选择集,返回值错误?
acedRetName(ss,RTPICKS);
acedSSFree(ss);
return (RSRSLT) ;
}
选择集用完是要释放掉的,
既然用arx了,干嘛还要用lsp? luowy 发表于 2013-8-14 10:51 static/image/common/back.gif
选择集用完是要释放掉的,
既然用arx了,干嘛还要用lsp?
自己搞定了,选择集要作为返回值传递给Lisp,就不能释放!
//连续画直线,返回选择集
static int ads_line1(void)
{
struct resbuf *pArgs =acedGetArgs () ;
//判断第一点
AcGePoint3d p1;
if (pArgs == NULL)
{
acdbFail(_T("\n参数错误"));
return RTERROR;
}
if (pArgs->restype == RTPOINT)
{
AcGePoint2d p;
p = asPnt2d(pArgs->resval.rpoint);
p1.set(p.x,p.y,0.0);
pArgs = pArgs->rbnext;
}
else if (pArgs->restype == RT3DPOINT)
{
p1 = asPnt3d(pArgs->resval.rpoint);
pArgs = pArgs->rbnext;
}
else
{
acdbFail(_T("\n参数错误"));
return RTERROR;
}
//判断第二点
AcGePoint3d p2;
if (pArgs == NULL)
{
acdbFail(_T("\n参数错误"));
return RTERROR;
}
if (pArgs->restype == RTPOINT)
{
AcGePoint2d p;
p = asPnt2d(pArgs->resval.rpoint);
p2.set(p.x,p.y,0.0);
pArgs = pArgs->rbnext;
}
else if (pArgs->restype == RT3DPOINT)
{
p2 = asPnt3d(pArgs->resval.rpoint);
pArgs = pArgs->rbnext;
}
else
{
acdbFail(_T("\n参数错误1"));
return RTERROR;
}
ads_name ent,ss;
AcDbObjectId IdLine;
IdLine = CCreateEnt::CreateLine(p1,p2);
acdbGetAdsName(ent,IdLine);
if (acedSSAdd(ent,NULL,ss) != RTNORM)
{
acdbFail(_T("\n实体添加错误1"));
return RTERROR;
}
p1 = p2;
while (pArgs != NULL)
{
if (pArgs->restype == RTPOINT)
{
AcGePoint2d p;
p = asPnt2d(pArgs->resval.rpoint);
p2.set(p.x,p.y,0.0);
pArgs = pArgs->rbnext;
}
else if (pArgs->restype == RT3DPOINT)
{
p2 = asPnt3d(pArgs->resval.rpoint);
pArgs = pArgs->rbnext;
}
else
{
acdbFail(_T("\n参数错误1"));
return RTERROR;
}
IdLine = CCreateEnt::CreateLine(p1,p2);
acdbGetAdsName(ent,IdLine);
if (acedSSAdd(ent,ss,ss) != RTNORM)
{
acdbFail(_T("\n实体添加错误2"));
return RTERROR;
}
p1 = p2;
}
acedRetName(ss,RTPICKS);
return (RSRSLT) ;
}
页:
[1]