明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1176|回复: 2

求助:自定义函数如何返回选择集

[复制链接]
发表于 2013-8-14 09:44 | 显示全部楼层 |阅读模式
本帖最后由 Lisper 于 2013-8-14 11:50 编辑

求助高手:
用arx自定义了一个函数,提供给Lisp调用,功能是连续绘制几条直线,然后将绘制的所有直线作为选择集传递给lisp作为返回值,请高手给下面的代码修改一下供学习!
谢谢!
下面是我的代码,但返回值不对:
  1. static int ads_line1(void)
  2. {
  3.    struct resbuf *pArgs =acedGetArgs () ;
  4.    //判断第一点
  5.    AcGePoint3d p1;
  6.    if (pArgs == NULL)
  7.    {
  8.      acdbFail(_T("\n参数错误"));
  9.      return RTERROR;
  10.    }
  11.    if (pArgs->restype == RTPOINT)
  12.    {
  13.      AcGePoint2d p;
  14.      p = asPnt2d(pArgs->resval.rpoint);
  15.       p1.set(p.x,p.y,0.0);
  16.      pArgs = pArgs->rbnext;
  17.    }
  18.    else if (pArgs->restype == RT3DPOINT)
  19.    {
  20.      p1 = asPnt3d(pArgs->resval.rpoint);
  21.      pArgs = pArgs->rbnext;
  22.    }
  23.    else
  24.    {
  25.      acdbFail(_T("\n参数错误"));
  26.      return RTERROR;
  27.    }
  28.    //判断第二点
  29.    AcGePoint3d p2;
  30.    if (pArgs == NULL)
  31.    {
  32.      acdbFail(_T("\n参数错误"));
  33.      return RTERROR;
  34.    }
  35.    if (pArgs->restype == RTPOINT)
  36.    {
  37.      AcGePoint2d p;
  38.      p = asPnt2d(pArgs->resval.rpoint);
  39.      p2.set(p.x,p.y,0.0);
  40.      pArgs = pArgs->rbnext;
  41.    }
  42.    else if (pArgs->restype == RT3DPOINT)
  43.    {
  44.      p2 = asPnt3d(pArgs->resval.rpoint);
  45.      pArgs = pArgs->rbnext;
  46.    }
  47.    else
  48.    {
  49.      acdbFail(_T("\n参数错误1"));
  50.      return RTERROR;
  51.    }
  52.    AcDbEntity *pEnt;
  53.    ads_name ent,ss,resSS;
  54.    AcDbObjectId IdLine;
  55.    IdLine = CCreateEnt::CreateLine(p1,p2);
  56.    acdbGetAdsName(ent,IdLine);
  57.    p1 = p2;
  58.    while (pArgs != NULL)
  59.    {
  60.      if (pArgs->restype == RTPOINT)
  61.      {
  62.        AcGePoint2d p;
  63.        p = asPnt2d(pArgs->resval.rpoint);
  64.        p2.set(p.x,p.y,0.0);
  65.        pArgs = pArgs->rbnext;
  66.      }
  67.      else if (pArgs->restype == RT3DPOINT)
  68.      {
  69.        p2 = asPnt3d(pArgs->resval.rpoint);
  70.        pArgs = pArgs->rbnext;
  71.      }
  72.      else
  73.      {
  74.        acdbFail(_T("\n参数错误1"));
  75.        return RTERROR;
  76.      }
  77.      IdLine = CCreateEnt::CreateLine(p1,p2);
  78.      acdbGetAdsName(ent,IdLine);
  79.     acedSSAdd(ent,ss,resSS);
  80.     ads_name_set(resSS,ss);
  81.      p1 = p2;

  82.    }
  83.    //返回选择集,返回值错误?
  84.   acedRetName(ss,RTPICKS);
  85. acedSSFree(ss);
  86.   return (RSRSLT) ;   
  87. }


发表于 2013-8-14 10:51 | 显示全部楼层
选择集用完是要释放掉的,
既然用arx了,干嘛还要用lsp?
 楼主| 发表于 2013-8-14 20:09 | 显示全部楼层
luowy 发表于 2013-8-14 10:51
选择集用完是要释放掉的,
既然用arx了,干嘛还要用lsp?

自己搞定了,选择集要作为返回值传递给Lisp,就不能释放!
  1. //连续画直线,返回选择集
  2. static int ads_line1(void)
  3. {
  4.          struct resbuf *pArgs =acedGetArgs () ;
  5.          //判断第一点
  6.          AcGePoint3d p1;
  7.          if (pArgs == NULL)
  8.          {
  9.                  acdbFail(_T("\n参数错误"));
  10.                  return RTERROR;
  11.          }
  12.          if (pArgs->restype == RTPOINT)
  13.          {
  14.                  AcGePoint2d p;
  15.                  p = asPnt2d(pArgs->resval.rpoint);
  16.                   p1.set(p.x,p.y,0.0);
  17.                  pArgs = pArgs->rbnext;
  18.          }
  19.          else if (pArgs->restype == RT3DPOINT)
  20.          {
  21.                  p1 = asPnt3d(pArgs->resval.rpoint);
  22.                  pArgs = pArgs->rbnext;
  23.          }
  24.          else
  25.          {
  26.                  acdbFail(_T("\n参数错误"));
  27.                  return RTERROR;
  28.          }
  29.          //判断第二点
  30.          AcGePoint3d p2;
  31.          if (pArgs == NULL)
  32.          {
  33.                  acdbFail(_T("\n参数错误"));
  34.                  return RTERROR;
  35.          }
  36.          if (pArgs->restype == RTPOINT)
  37.          {
  38.                  AcGePoint2d p;
  39.                  p = asPnt2d(pArgs->resval.rpoint);
  40.                  p2.set(p.x,p.y,0.0);
  41.                  pArgs = pArgs->rbnext;
  42.          }
  43.          else if (pArgs->restype == RT3DPOINT)
  44.          {
  45.                  p2 = asPnt3d(pArgs->resval.rpoint);
  46.                  pArgs = pArgs->rbnext;
  47.          }
  48.          else
  49.          {
  50.                  acdbFail(_T("\n参数错误1"));
  51.                  return RTERROR;
  52.          }
  53.     ads_name ent,ss;
  54.    AcDbObjectId IdLine;
  55.    IdLine = CCreateEnt::CreateLine(p1,p2);
  56.    acdbGetAdsName(ent,IdLine);
  57.    if (acedSSAdd(ent,NULL,ss) != RTNORM)
  58.    {
  59.            acdbFail(_T("\n实体添加错误1"));
  60.            return RTERROR;
  61.    }
  62.    p1 = p2;
  63.    while (pArgs != NULL)
  64.    {
  65.            if (pArgs->restype == RTPOINT)
  66.            {
  67.                    AcGePoint2d p;
  68.                    p = asPnt2d(pArgs->resval.rpoint);
  69.                    p2.set(p.x,p.y,0.0);
  70.                    pArgs = pArgs->rbnext;
  71.            }
  72.            else if (pArgs->restype == RT3DPOINT)
  73.            {
  74.                    p2 = asPnt3d(pArgs->resval.rpoint);
  75.                    pArgs = pArgs->rbnext;
  76.            }
  77.            else
  78.            {
  79.                    acdbFail(_T("\n参数错误1"));
  80.                    return RTERROR;
  81.            }
  82.            IdLine = CCreateEnt::CreateLine(p1,p2);
  83.            acdbGetAdsName(ent,IdLine);
  84.            if (acedSSAdd(ent,ss,ss) != RTNORM)
  85.            {
  86.                    acdbFail(_T("\n实体添加错误2"));
  87.                    return RTERROR;
  88.            }
  89.            p1 = p2;

  90.    }

  91.    acedRetName(ss,RTPICKS);
  92. return (RSRSLT) ;          
  93. }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-5 18:28 , Processed in 1.429929 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表