设为首页收藏本站

中国膜结构网

 找回密码
 立即注册
膜结构车棚
膜结构车棚膜结构资质国产膜材 膜结构网中国膜结构协会
查看: 41|回复: 0

命令pedit实现的连接LINE/ARC到POLYLINE的代码

[复制链接]
  • TA的每日心情
    开心
    2021-3-7 10:01
  • 签到天数: 1440 天

    连续签到: 19 天

    [LV.10]以坛为家III

    发表于 2021-2-23 07:17 | 显示全部楼层 |阅读模式
    http://www.mjgw.org/ 专业从事膜结构设计、制作加工、施工安装的膜结构咨询服务,能够为客户提供专业的膜结构整体解决方案。做中国最好的膜结构综合服务平台。欢迎大家联系QQ:463017170.
    1. 下面是使用命令pedit实现的连接LINE/ARC到POLYLINE的代码:

    2. [mw_shl_code=cpp,true]//-----------------------------------------------------------------------------
    3. //----- acrxEntryPoint.cpp
    4. //-----------------------------------------------------------------------------
    5. #include "StdAfx.h"
    6. #include "acedCmdNF.h"
    7. #include "resource.h"
    8. //-----------------------------------------------------------------------------
    9. #define szRDS _RXST("")
    10. //-----------------------------------------------------------------------------
    11. //----- ObjectARX EntryPoint
    12. class CMyJoinApp : public AcRxArxApp {

    13. public:
    14.   CMyJoinApp() : AcRxArxApp() {}
    15.   virtual AcRx::AppRetCode On_kInitAppMsg(void *pkt) {
    16.     AcRx::AppRetCode retCode = AcRxArxApp::On_kInitAppMsg(pkt);
    17.     return (retCode);
    18.   }
    19.   virtual AcRx::AppRetCode On_kUnloadAppMsg(void *pkt) {
    20.     AcRx::AppRetCode retCode = AcRxArxApp::On_kUnloadAppMsg(pkt);
    21.     return (retCode);
    22.   }
    23.   virtual void RegisterServerComponents() {}

    24.   static void RivilisMyJoin() {
    25.     ads_name en1;  ads_point p;
    26.     while (acedEntSel(_T("\nSelect first segment: "), en1, p) == RTNORM)
    27.     {
    28.       bool bConvertToPoly = false;
    29.       AcDbObjectId id1; acdbGetObjectId(id1, en1);
    30.       if (id1.objectClass() == AcDbLine::desc() ||
    31.           id1.objectClass() == AcDbArc::desc())
    32.       {
    33.         bConvertToPoly = true;
    34.       }
    35.       ads_name en2;
    36.       if (acedEntSel(_T("\nSelect next segment: "), en2, p) == RTNORM)
    37.       {
    38.         if (bConvertToPoly)
    39.           acedCommandS(RTSTR, _T("_PEDIT"), RTENAME, en1, RTSTR, _T("_YES"), RTSTR, _T("_Join"),
    40.             RTENAME, en2, RTSTR, _T(""), RTSTR, _T(""), RTNONE);
    41.         else
    42.           acedCommandS(RTSTR, _T("_PEDIT"), RTENAME, en1, RTSTR, _T("_Join"),
    43.             RTENAME, en2, RTSTR, _T(""), RTSTR, _T(""), RTNONE);
    44.       }
    45.     }
    46.   }
    47. };

    48. //-----------------------------------------------------------------------------
    49. IMPLEMENT_ARX_ENTRYPOINT(CMyJoinApp)

    50. ACED_ARXCOMMAND_ENTRY_AUTO(CMyJoinApp, Rivilis, MyJoin, MyJoin, ACRX_CMD_MODAL, NULL)[/mw_shl_code]


    51. 下面是不用命令实现的连接LINE/ARC到POLYLINE的代码

    52. 本帖隐藏的内容
    53. [mw_shl_code=cpp,true]//-----------------------------------------------------------------------------
    54. //----- acrxEntryPoint.cpp
    55. //-----------------------------------------------------------------------------
    56. #include "StdAfx.h"
    57. #include "resource.h"

    58. //-----------------------------------------------------------------------------
    59. #define szRDS _RXST("")

    60. //-----------------------------------------------------------------------------
    61. //----- ObjectARX EntryPoint
    62. class CJoinToPlineApp : public AcRxArxApp {

    63. public:
    64.   CJoinToPlineApp () : AcRxArxApp () {}

    65.   virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
    66.     AcRx::AppRetCode retCode = AcRxArxApp::On_kInitAppMsg (pkt) ;
    67.     return (retCode) ;
    68.   }

    69.   virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
    70.     AcRx::AppRetCode retCode = AcRxArxApp::On_kUnloadAppMsg (pkt) ;
    71.     return (retCode) ;
    72.   }

    73.   virtual void RegisterServerComponents () {
    74.   }

    75.   static void JoinToPlineJoinToPline () {
    76.     // Фильтр для выбора отрезков (LINE) и дуг (ARC)
    77.     ACHAR* promptPtrs[] = {
    78.       _T("\nSelect lines and arcs for join in poyline (ENTER - exit): "),
    79.       _T("\nRemove lines and arcs from selection set: ")
    80.     };

    81.     ads_name ss;
    82.     resbuf *rbFilter = acutBuildList(RTDXF0,_T("LINE,ARC"),RTNONE);
    83.     int rc = acedSSGet(_T(":$"),promptPtrs,NULL,rbFilter,ss);
    84.     acutRelRb(rbFilter);

    85.     if (rc != RTNORM) return;

    86.     AcDbObjectIdArray ids;
    87.     if (ObjectIdArrayFromSelSet(ss, ids) != Acad::eOk) return;
    88.     while (ids.length() > 0)
    89.     {
    90.       AcDbEntity *p = MakeJonedPoly(ids);
    91.       if (p) {
    92.         AcDbBlockTableRecordPointer pSpace(acdbCurDwg()->currentSpaceId(), AcDb::kForWrite);
    93.         if (pSpace.openStatus() != Acad::eOk) return;
    94.         pSpace->appendAcDbEntity(p);
    95.         p->close();
    96.       } else {
    97.         acutPrintf(_T("\nError in data!"));
    98.         return;
    99.       }
    100.     }

    101.   }

    102.   /// <summary>
    103.   /// AcDbObjectIdArray from SelectionSet
    104.   /// </summary>
    105.   /// <param name="sset">SelectionSet</param>
    106.   /// <param name="ids">AcDbObjectIdArray</param>
    107.   /// <returns></returns>
    108.   static Acad::ErrorStatus ObjectIdArrayFromSelSet(ads_name sset, AcDbObjectIdArray &ids)
    109.   {
    110.     Acad::ErrorStatus es = Acad::eOk;
    111.     long nset = -1;
    112.     if (acedSSLength(sset,&nset) != RTNORM) return Acad::eAmbiguousInput;
    113.     ids.setLogicalLength(nset);
    114.     ads_name en;
    115.     AcDbObjectId id;
    116.     for (long i=0; i < nset; i++) {
    117.       if (acedSSName(sset,i,en) == RTNORM) {
    118.         if ((es = acdbGetObjectId(id,en)) != Acad::eOk) return es;
    119.         ids = id;
    120.       }
    121.     }
    122.     return Acad::eOk;
    123.   }

    124.   /// <summary>
    125.   /// Create polyline from lines and arcs.
    126.   /// Those ids will remove from input array
    127.   /// </summary>
    128.   /// <param name="ids">Array of id's</param>
    129.   /// <param name="FUZZ">The accuracy of determining the distance between points</param>
    130.   /// <returns></returns>
    131.   static AcDbPolyline* MakeJonedPoly(
    132.     AcDbObjectIdArray &ids,
    133.     double FUZZ = AcGeContext::gTol.equalPoint())
    134.   {
    135.     AcDbPolyline *p = new AcDbPolyline();
    136.     p->setDatabaseDefaults();
    137.     AcDbObjectId idFirst = ids[0];
    138.     AcGePoint3d nextPt = AcGePoint3d::kOrigin;
    139.     AcGePoint3d prevPt = AcGePoint3d::kOrigin;

    140.     AcDbObjectPointer<AcDbCurve> c(idFirst,AcDb::kForRead);
    141.     if (c.openStatus() == Acad::eOk) {
    142.       AcGePoint3d ptStart, ptEnd;
    143.       c->getStartPoint(ptStart); c->getEndPoint(ptEnd);
    144.       p->addVertexAt(0, asPnt2d(asDblArray(ptStart)), BulgeFromArc(c, false), 0, 0);
    145.       p->addVertexAt(1, asPnt2d(asDblArray(ptEnd)), 0, 0, 0);
    146.       nextPt = ptEnd;
    147.       prevPt = ptStart;
    148.     }

    149.     ids.remove(idFirst);
    150.     int prevCnt = ids.length() + 1;

    151.     while (ids.length() > 0 && ids.length() < prevCnt)
    152.     {
    153.       prevCnt = ids.length();
    154.       for (int i = 0; i < ids.length(); i++) {
    155.         AcDbObjectId id = ids;
    156.         AcDbObjectPointer<AcDbCurve> cv(id,AcDb::kForRead);
    157.         if (cv.openStatus() == Acad::eOk) {
    158.           AcGePoint3d ptStart, ptEnd;
    159.           cv->getStartPoint(ptStart); cv->getEndPoint(ptEnd);
    160.           if (ptStart.distanceTo(nextPt) < FUZZ || ptEnd.distanceTo(nextPt) < FUZZ) {
    161.             double bulge = BulgeFromArc(cv, ptEnd.distanceTo(nextPt) < FUZZ);
    162.             p->setBulgeAt(p->numVerts() - 1, bulge);
    163.             if (ptStart.distanceTo(nextPt) < FUZZ)
    164.               nextPt = ptEnd;
    165.             else
    166.               nextPt = ptStart;
    167.             p->addVertexAt(p->numVerts(), asPnt2d(asDblArray(nextPt)), 0, 0, 0);
    168.             ids.remove(id);
    169.             break;
    170.           } else if (ptStart.distanceTo(prevPt) < FUZZ || ptEnd.distanceTo(prevPt) < FUZZ) {
    171.             double bulge = BulgeFromArc(cv, ptStart.distanceTo(prevPt) < FUZZ);
    172.             if (ptStart.distanceTo(prevPt) < FUZZ)
    173.               prevPt = ptEnd;
    174.             else
    175.               prevPt = ptStart;
    176.             p->addVertexAt(0, asPnt2d(asDblArray(prevPt)), bulge, 0, 0);
    177.             ids.remove(id);
    178.             break;
    179.           }
    180.         }
    181.       }
    182.     }
    183.     if (p->numVerts() == 0) {
    184.       delete p;  return NULL;
    185.     }  else  {
    186.       return p;
    187.     }
    188.   }

    189.   /// <summary>
    190.   /// Getting bulge of curve
    191.   /// </summary>
    192.   /// <param name="c">AcDbCurve pointer</param>
    193.   /// <param name="clockwise">direction.</param>
    194.   /// <returns></returns>
    195.   static double BulgeFromArc(AcDbCurve *c, bool clockwise)
    196.   {
    197.     double bulge = 0.0;
    198.     AcDbArc *a = AcDbArc::cast(c);
    199.     if (a == NULL) return bulge;

    200.     double newStart =
    201.       (a->startAngle() > a->endAngle()) ?
    202.       (a->startAngle() - 8 * atan(1.0)) :
    203.       (a->startAngle());

    204.     bulge = tan((a->endAngle() - newStart) / 4.0);
    205.     if (clockwise) bulge = -bulge;
    206.     return bulge;
    207.   }
    208. } ;

    209. //-----------------------------------------------------------------------------
    210. IMPLEMENT_ARX_ENTRYPOINT(CJoinToPlineApp)
    211. ACED_ARXCOMMAND_ENTRY_AUTO(CJoinToPlineApp, JoinToPline, JoinToPline, JoinToPline, ACRX_CMD_MODAL, NULL)[/mw_shl_code]
    复制代码
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    关闭

    推荐膜材品牌上一条 /5 下一条

    进口膜材 国产膜材 pvdf膜材ptfe膜材ETFE膜材
    最好的膜结构公司 一级膜结构资质 膜结构一级资质
    膜结构设计-膜结构十大品牌-etfe设计-充气膜结构
    诺科膜结构
    遨都膜结构设计
    中国膜结构网
    中国空间膜结构协会

    QQ|申请友链|Archiver|手机版|中国膜结构论坛

    GMT+8, 2021-3-8 02:15 , Processed in 0.287547 second(s), 27 queries .

    Powered by 中国膜结构网->膜材采购->膜结构设计->膜结构安装->膜结构维修

    © 2014-2020 膜结构协会->进口膜材->国产膜材->PVDF膜材->PTFE膜材->ETFE膜材.

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