找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 176|回复: 0

[每日一码] 模拟实现STRETCH命令的ARX实现代码

[复制链接]

0

主题

0

回帖

26

积分

管理员

积分
26
发表于 2024-2-23 22:36:47 | 显示全部楼层 |阅读模式
  1. void asdktest()
  2. {
  3. AcGePoint3d pnt1;
  4. // get the first point
  5. int res = acedGetPoint (NULL, "\nPick crossing window : ", asDblArray (pnt1));
  6. // if ok
  7. if (res == RTNORM)
  8. {
  9.   AcGePoint3d pnt2;
  10.   res = acedGetCorner (asDblArray (pnt1), "\nSpecify other corner : ", asDblArray (pnt2));
  11.   // if ok
  12.   if (res == RTNORM)
  13.   {
  14.    AcGePoint3d distPnt;
  15.    res = acedGetPoint (asDblArray (pnt1), "\nPick distance : ", asDblArray (distPnt));
  16.    // if ok
  17.    if (res == RTNORM)
  18.    {
  19.     // get the stretch distance
  20.     AcGeVector3d stretchVec = distPnt - pnt1;
  21.     // create a bounding box - we have to use the set method like this because of
  22.     // a defect in the other set method :-(
  23.     AcGeBoundBlock3d box;
  24.     box.set (pnt1, AcGeVector3d ((pnt2-pnt1).x, 0,0),
  25.             AcGeVector3d (0,(pnt2-pnt1).y,0),
  26.             AcGeVector3d (0,0,(pnt2-pnt1).z));
  27.     ads采用name ss;
  28.     // get a strech selection set
  29.     res = acedSSGet ("采用C", asDblArray (pnt1), asDblArray (pnt2), NULL, ss);
  30.     // if ok
  31.     if (res == RTNORM)
  32.     {
  33.      // get the length of the selection set
  34.      long length = 0l;
  35.      acedSSLength (ss, &length);
  36.      // now loop round
  37.      for (long i=0; i<length; ++i)
  38.      {
  39.       ads采用name ename;
  40.       // extract the ename
  41.       if (acedSSName (ss, i, ename) != RTNORM)
  42.        continue;
  43.       AcDbObjectId id;
  44.       // convert the ename into an ObjectId
  45.       acdbGetObjectId(id, ename);
  46.       // open the entity for write
  47.       AcDbObjectPointer<AcDbEntity>ent (id, AcDb::kForWrite);
  48.       // if ok
  49.       if (ent.openStatus() == Acad::eOk)
  50.       {
  51.        AcGePoint3dArray pnts;
  52.        // get the stretch points
  53.        if (ent->getStretchPoints(pnts) != Acad::eOk)
  54.         continue;
  55.        // find out what points need processing
  56.        AcDbIntArray idxAry;
  57.        bool found = false;
  58.        for (int i=0; i<pnts.length(); ++i)
  59.        {
  60.         // get one of the stretch points
  61.         AcGePoint3d pnt = pnts.at(i);
  62.         // if the point is in the crossing window
  63.         if (box.contains(pnt))
  64.         {
  65.          // add it to our list
  66.          idxAry.append(i);
  67.          found = true;
  68.         }
  69.        }
  70.        // if the stretch is valid
  71.        if (found || pnts.length() == 0)
  72.        {
  73.         // then update the points!!
  74.         ent->moveStretchPointsAt(idxAry, stretchVec);
  75.        }      
  76.       }
  77.      }
  78.      // free up the selection set
  79.      acedSSFree (ss);
  80.     }
  81.    }
  82.   }
  83. }
  84. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2024-12-28 14:54 , Processed in 0.142424 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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