天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 64|回复: 1

加入组

[复制链接]
  • TA的每日心情
    开心
    昨天 09:51
  • 签到天数: 80 天

    [LV.6]常住居民II

    1543

    主题

    202

    回帖

    214748万

    积分

    管理员

    积分
    2147483647
    发表于 2024-3-29 22:48:08 | 显示全部楼层 |阅读模式
    1. static void  MyGroupMyCommand()
    2. {
    3.         ads_name ent, entg;
    4.         ads_point pt;
    5.         if (RTNORM != acedEntSel(_T("\nSelect objects to join the group: "), ent, pt))
    6.                 return;
    7.         if (RTNORM != acedEntSel(_T("\nSelect Group: "), entg, pt))
    8.                 return;

    9.         AcDbObjectId objIdInGroup, objId, GroupId;  //TB objIdInGroup
    10.         if (acdbGetObjectId(objId, ent) != Acad::eOk)        return;
    11.         if (acdbGetObjectId(objIdInGroup, entg) != Acad::eOk)        return; //TB GroupId-->objIdInGroup

    12.         CString GName;
    13.         AcDbObjectIdArray entIds, GroupentIds;
    14.         IdGetGroupname(objIdInGroup, GName, GroupentIds, GroupId); // objId-->objIdInGroup

    15.         entIds.append(objId);
    16.         IdsAddGroup(GroupId, entIds);
    17. }



    18. void   IdsAddGroup(const AcDbObjectId groupId, AcDbObjectIdArray &entIds)
    19. {
    20.    if (!entIds.isEmpty())       
    21.    {  
    22.             Acad::ErrorStatus es;
    23.                 AcDbGroup* group;
    24.                 if ((es = acdbOpenObject(group, groupId, AcDb::kForWrite)) == Acad::eOk)
    25.                 {
    26.                    group->append(entIds);
    27.                    group->close();
    28.                 }
    29.         }
    30. }


    复制代码

     

     

     

     

    加入组
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
  • TA的每日心情
    开心
    昨天 09:51
  • 签到天数: 80 天

    [LV.6]常住居民II

    1543

    主题

    202

    回帖

    214748万

    积分

    管理员

    积分
    2147483647
     楼主| 发表于 2024-3-29 22:51:59 | 显示全部楼层
    删除组 A1 中的文本,增加弧长并将文本添加到组 A1?

    1. static void MSDDMyGroupMyCommand0() {
    2.         ads_name ent;
    3.         ads_point pt;
    4.         if (RTNORM != acedEntSel(_T("\n选择对象: "), ent, pt))
    5.                 return;
    6.         AcDbObjectId objId;
    7.         acdbGetObjectId(objId, ent);
    8.         AcDbEntityPointer pEntPtr(objId, AcDb::kForRead); //tb: renamed to avoid confusion with pEnt below
    9.         Acad::ErrorStatus es = pEntPtr.openStatus();
    10.         if (Acad::eOk != es)
    11.         {
    12.                 acutPrintf(_T("\nFailed to open object,es=%s"), acadErrorStatusText(es));
    13.                 return;
    14.         }

    15.         const AcDbVoidPtrArray* pReactors = pEntPtr->reactors();
    16.         if (pReactors == NULL || pReactors->length() < 1)
    17.         {
    18.                 acutPrintf(_T("\nThe object has no groups!"));
    19.                 return;
    20.         }
    21.         AcDbObjectIdArray entIds;
    22.         for (int i = 0; i < pReactors->length(); i++)
    23.         {
    24.                 void* pSomething = pReactors->at(i);
    25.                 if (pSomething == NULL) continue;
    26.                 if (!acdbIsPersistentReactor(pSomething)) continue;
    27.                 AcDbObjectId persReactorId = acdbPersistentReactorObjectId(pSomething);
    28.                 AcDbObjectPointer<AcDbGroup> pGroup(persReactorId, AcDb::kForRead);
    29.                 pGroup->allEntityIds(entIds);
    30.         }
    31.         //tb: You are using AcDbEntityPointer pEnt above and
    32.         // AcDbEntity* pEnt; below. I would suggest to choose different names!
    33.         // The problem is, that the AcDbEntityPointer pEnt keeps the entity open for read
    34.         // until it goes out of scope.
    35.         // This causes that you can't open AcDbEntity* pEnt for write.
    36.         pEntPtr->close(); //tb: close it here explicitly.

    37.         for (int i = 0; i < entIds.length(); i++)
    38.         {
    39.                 AcDbEntity* pEnt = NULL; //tb: Confusing! NOT the same as AcDbEntityPointer pEnt above!
    40.                 //tb: It is always a good idea to store the Acad::ErrorStatus.
    41.                 // It gives important information if something goes wrong.
    42.                 // You should only open objects for write, if you really need to modify them.
    43.                 Acad::ErrorStatus es = acdbOpenObject(pEnt, entIds.at(i), AcDb::kForRead); //tb: Write->Read
    44.                 if (es == Acad::eOk)
    45.                 {
    46.                         if (pEnt->isKindOf(AcDbText::desc()))
    47.                         {
    48.                                 //tb: Here we need write acces. So we upgradeOpen() the entity.
    49.                                 es = pEnt->upgradeOpen();
    50.                                 if (es==Acad::eOk)
    51.                                         pEnt->erase();
    52.                         }
    53.                         else
    54.                         {
    55.                                 double PaPtCen;
    56.                                 AcGePoint3d PtCen;
    57.                                 WCHAR s[20];

    58.                                 // pEnt->close();
    59.                                 //tb: no need to reopen the entity.
    60.                                 // The 3rd usage of the variable name pEnt gave extra confusion!
    61.                                 AcDbCurve* pCurve = AcDbCurve::cast(pEnt);
    62.                                 if (pCurve) // AcDbCurve::cast(pEnt) returns NULL if it isn't an AcDbCurve
    63.                                 {
    64.                                         double startParam, endParam, startDist, endDist;
    65.                                         pCurve->getStartParam(startParam);
    66.                                         pCurve->getEndParam(endParam);
    67.                                         pCurve->getDistAtParam(startParam, startDist);
    68.                                         pCurve->getDistAtParam(endParam, endDist);
    69.                                         double Clength = endDist - startDist;
    70.                                         pCurve->getParamAtDist(Clength * 0.5, PaPtCen);
    71.                                         pCurve->getPointAtParam(PaPtCen, PtCen);
    72.                                         _swprintf(s, L"L=%0.0f", Clength);

    73.                                         AcDbText* text = new AcDbText(PtCen, s, AcDbObjectId::kNull, 80, 0);
    74.                                         text->setColorIndex(50);
    75.                                         text->setWidthFactor(0.7);

    76.                                         text->setHorizontalMode(AcDb::TextHorzMode::kTextCenter);
    77.                                         text->setAlignmentPoint(PtCen);
    78.                                         text->setJustification(AcDbText::kTextAlignmentMiddleCenter);

    79.                                         AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
    80.                                         AcDbBlockTableRecordPointer pBTR(pDb->currentSpaceId(), AcDb::kForWrite);
    81.                                         if (text && Acad::eOk == pBTR.openStatus()) {
    82.                                                 pBTR->appendAcDbEntity(text); text->close();
    83.                                         }
    84.                                 }
    85.                         }
    86.                         pEnt->close(); //tb: moved here.
    87.                 }
    88.                 //pEnt->close(); //tb: only close what you have opened!
    89.         }
    90. }



    91. AcDbObjectIdArray entIds, newTextIds; //tb: store text ids in newTextIds
    92.         AcDbObjectId groupId; //tb: Store the group id here
    93.         for (int i = 0; i < pReactors->length(); i++)        {
    94.                 void* pSomething = pReactors->at(i);
    95.                 if (pSomething == NULL) continue;
    96.                 if (!acdbIsPersistentReactor(pSomething)) continue;
    97.                 AcDbObjectId persReactorId = acdbPersistentReactorObjectId(pSomething);
    98.                 AcDbObjectPointer<AcDbGroup> pGroup(persReactorId, AcDb::kForRead);
    99.                 if (pGroup.object()) //tb: Better check. There might be other persistent reactors
    100.                 {
    101.                         groupId = pGroup->objectId(); //tb: Store group id for later
    102.                         pGroup->allEntityIds(entIds);
    103.                 }
    104.         }
    105. ...
    106.                                         if (text && Acad::eOk == pBTR.openStatus()) {
    107.                                                 es = pBTR->appendAcDbEntity(text);
    108.                                                 if (es == Acad::eOk)        {
    109.                                                         newTextIds.append(text->objectId()); //tb: Store the id
    110.                                                         text->close();
    111.                                                 }
    112.                                                 else
    113.                                                         delete text;
    114.                                         }

    115. ...

    116.         if (!newTextIds.isEmpty())        { //tb: Append the new text entities to the group.
    117.                 AcDbGroup* group;
    118.                 if ((es = acdbOpenObject(group, groupId, AcDb::kForWrite)) == Acad::eOk) {
    119.                         group->append(newTextIds);
    120.                         group->close();
    121.                 }
    122.         }
    复制代码

     

     

     

     

    加入组
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网_中国空间膜结构协会

    GMT+8, 2024-5-14 02:53 , Processed in 0.057639 second(s), 21 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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