找回密码
 立即注册

QQ登录

只需一步,快速开始

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

AcDbSection 从正面创建实体的 2D 轮廓

[复制链接]

0

主题

0

回帖

26

积分

管理员

积分
26
发表于 2024-3-5 08:11:41 | 显示全部楼层 |阅读模式
  1. void ClearCollection(AcArray<AcDbEntity *> &arr)
  2. {
  3.     for (AcDbEntity *ent : arr) {
  4.         if (ent) {
  5.             if (!ent->database())
  6.                 delete ent;
  7.             else
  8.                 ent->close();
  9.         }
  10.     }
  11.     arr.setLogicalLength(0);
  12. }
  13. Acad::ErrorStatus appendWithColor(AcArray<AcDbEntity *> &arr,
  14.                                   AcDbBlockTableRecord *btr, uint16采用t col)
  15. {
  16.     Acad::ErrorStatus esRet = Acad::eOk, es;
  17.     for (AcDbEntity *ent : arr) {
  18.         if (ent != nullptr) {
  19.             // Note that my implementation of ClearCollection() just close()s
  20.             // DB-resident entities Non resident entities will be deleted.
  21.             ent->setDatabaseDefaults(btr->database());
  22.             ent->setColorIndex(col);
  23.             es = btr->appendAcDbEntity(ent);
  24.             // we don't close ent!
  25.             if (es) esRet = es;
  26.         }
  27.     }
  28.     return esRet;
  29. }
  30. void cgsa采用section()
  31. {
  32.     Acad::ErrorStatus es;
  33.     AcDb3dSolid *solid = nullptr;
  34.     ads采用name ename;
  35.     ads采用point pt;
  36.     if (acedEntSel(L"\nPick a solid: ", ename, pt) != RTNORM) return;
  37.     AcDbObjectId idSolid;
  38.     es = acdbGetObjectId(idSolid, ename);
  39.     if (!es) {
  40.         es = acdbOpenObject(solid, idSolid);
  41.         if (!es) {
  42.         }
  43.     }
  44.     else
  45.         return;
  46.     AcDbExtents extents;
  47.     solid->getGeomExtents(extents);
  48.     auto minX = extents.minPoint().x;
  49.     auto minY = extents.minPoint().y;
  50.     auto minZ = extents.minPoint().z;
  51.     auto maxX = extents.maxPoint().x;
  52.     auto maxY = extents.maxPoint().y;
  53.     auto maxZ = extents.maxPoint().z;
  54.     AcGePoint3dArray sectVertices;
  55.     sectVertices.append(AcGePoint3d(minX, minY, minZ));
  56.     sectVertices.append(AcGePoint3d(minX, maxY, minZ));
  57.     AcDbDatabase *db = solid->database();
  58.     AcDbSection *pSection = new AcDbSection(sectVertices, AcGeVector3d::kZAxis);
  59.     pSection->setDatabaseDefaults(db);
  60.     AcDbSection &section = *pSection;
  61.     AcDbSectionSettings* pSettings;
  62.     section.getSettings(pSettings, AcDb::kForWrite);
  63.     section.setState(AcDbSection::kPlane);
  64.         es = pSection->setHeight(AcDbSection::kHeightAboveSectionLine, 100);
  65.     es = pSection->setHeight(AcDbSection::kHeightBelowSectionLine, -100);
  66.     AcArray<AcDbEntity *> intBoundaryEnts;
  67.     AcArray<AcDbEntity *> intFillEnts;
  68.     AcArray<AcDbEntity *> backgroundEnts;
  69.     AcArray<AcDbEntity *> foregroundEnts;
  70.     AcArray<AcDbEntity *> curveTangencyEnts;
  71.     es = section.generateSectionGeometry(solid, intBoundaryEnts, intFillEnts,
  72.                                          backgroundEnts, foregroundEnts,
  73.                                          curveTangencyEnts);
  74.     if (es == Acad::eOk) {
  75.         AcGeMatrix3d mat;
  76.         mat.setToTranslation(AcGeVector3d(1000, 0, 0));
  77.         AcDbObjectId idModelSpace = acdbSymUtil()->blockModelSpaceId(db);
  78.         AcDbBlockTableRecord *modelspace;
  79.         es = acdbOpenObject(modelspace, idModelSpace, AcDb::kForWrite);
  80.         if (!es) {
  81.             es = modelspace->appendAcDbEntity(pSection);
  82.             if (!es)
  83.                 pSection->close();
  84.             else
  85.                 delete pSection;
  86.             appendWithColor(intBoundaryEnts, modelspace, 1);
  87.             appendWithColor(intFillEnts, modelspace, 2);
  88.             appendWithColor(backgroundEnts, modelspace, 3);
  89.             appendWithColor(foregroundEnts, modelspace, 4);
  90.             appendWithColor(curveTangencyEnts, modelspace, 5);
  91.             modelspace->close();
  92.         }
  93.     }
  94.     ClearCollection(intBoundaryEnts);
  95.     ClearCollection(intFillEnts);
  96.     ClearCollection(backgroundEnts);
  97.     ClearCollection(foregroundEnts);
  98.     ClearCollection(curveTangencyEnts);
  99. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-12-28 15:03 , Processed in 0.133689 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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