找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1504|回复: 0

[填充] AcDbHatch associativity

[复制链接]

已领礼包: 40个

财富等级: 招财进宝

发表于 2021-1-21 00:07:04 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
AcDbHatch associativity

问题:

After I made a hatch object, added it to the database, set the style, and so on, it is not associative to the object. What must I do to make it associative?

解答:
Use the hatch object that was just created as a persistent reactor for the entities to which it is hatching. The following sample demonstrates how to create a hatch and associate it to the boundary entities (a rectangle and a circle).

  1. static Acad::ErrorStatus postToDb(AcDbEntity* ent, AcDbObjectId& objId)
  2. {
  3. Acad::ErrorStatus es;
  4. AcDbBlockTable* pBlockTable;
  5. AcDbBlockTableRecord* pSpaceRecord;
  6. if (ent==NULL)
  7.   return Acad::eNullObjectPointer;
  8. if (acdbHostApplicationServices()->workingDatabase()==NULL)
  9.   return Acad::eNoDatabase;
  10. if ((es = acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead))!=Acad::eOk)
  11.   return es;
  12. if ((es =pBlockTable->getAt(ACDB_MODEL_SPACE,pSpaceRecord,AcDb::kForWrite)) != Acad::eOk)
  13. {
  14.   pBlockTable->close();
  15.   return es;
  16. }
  17. pBlockTable->close();
  18. if ((es = pSpaceRecord->appendAcDbEntity(objId, ent)) != Acad::eOk)
  19. { pSpaceRecord->close();
  20. return es;
  21. }
  22. pSpaceRecord->close();
  23. return ent->close();
  24. }


  25. static void Test()
  26. {
  27. AcDbHatch* pHatch = new AcDbHatch();
  28. // Set hatch plane
  29. AcGeVector3d normal(0.0, 0.0, 1.0);
  30. pHatch->setNormal(normal);
  31. pHatch->setElevation(0.0);
  32. // Set hatch pattern to ANSI31 predefined type //
  33. pHatch->setPattern(AcDbHatch::kPreDefined, _T("ANSI31"));
  34. // Set Associativity
  35. pHatch->setAssociative(Adesk::kTrue);
  36. // Construct database AcDbLines
  37. AcGePoint3d vertexPts[4];
  38. AcDbObjectId lineId, cirId, hatchId;
  39. AcDbObjectIdArray dbObjIds;
  40. AcDbLine *line;
  41. vertexPts[0].set(2.0, 2.0, 0.0);
  42. vertexPts[1].set(8.0, 2.0, 0.0);
  43. vertexPts[2].set(8.0, 8.0, 0.0);
  44. vertexPts[3].set(2.0, 8.0, 0.0);
  45. for (int i = 0; i < 4; i++)
  46. {
  47.   line = new AcDbLine();
  48.   line->setStartPoint(vertexPts);
  49.   line->setEndPoint(vertexPts[(i == 3) ? 0 : i+1]);
  50.   postToDb(line, lineId);
  51.   dbObjIds.append(lineId);
  52. }
  53. // Append an external rectangular loop to hatch boundary //
  54. pHatch->appendLoop(AcDbHatch::kExternal, dbObjIds);
  55. // Create a AcDbCircle and post it to database //
  56. AcGePoint3d cenPt(5.0, 5.0, 0.0);
  57. normal.set(0.0, 0.0, 1.0);
  58. AcDbCircle *circle = new AcDbCircle();
  59. circle->setNormal(normal);
  60. circle->setCenter(cenPt);
  61. circle->setRadius(1.0);
  62. postToDb(circle, cirId);
  63. dbObjIds.setLogicalLength(0);
  64. dbObjIds.append(cirId);
  65. // Append an internal loop (circle) to hatch boundary //
  66. pHatch->appendLoop(AcDbHatch::kDefault, dbObjIds);
  67. // Elaborate hatch lines
  68. pHatch->evaluateHatch();
  69. // Get all associative source boundary object Ids for later use. //
  70. dbObjIds.setLogicalLength(0);
  71. pHatch->getAssocObjIds(dbObjIds);
  72. // Post hatch entity to database
  73. postToDb(pHatch, hatchId);
  74. // Attach hatchId to all source boundary objects for notification. //
  75. AcDbEntity *pEnt;
  76. int numObjs = dbObjIds.length();
  77. for (int i = 0; i < numObjs; i++)
  78. {
  79.   if (acdbOpenAcDbEntity(pEnt, dbObjIds,AcDb::kForWrite)==Acad::eOk)
  80.   {
  81.    pEnt->addPersistentReactor(hatchId);
  82.    pEnt->close();
  83.   }
  84. }
  85. }


论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-12-14 17:39 , Processed in 0.353493 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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