- UID
- 5280
- 积分
- 9466
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-5-18
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
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).
- static Acad::ErrorStatus postToDb(AcDbEntity* ent, AcDbObjectId& objId)
- {
- Acad::ErrorStatus es;
- AcDbBlockTable* pBlockTable;
- AcDbBlockTableRecord* pSpaceRecord;
- if (ent==NULL)
- return Acad::eNullObjectPointer;
- if (acdbHostApplicationServices()->workingDatabase()==NULL)
- return Acad::eNoDatabase;
- if ((es = acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead))!=Acad::eOk)
- return es;
- if ((es =pBlockTable->getAt(ACDB_MODEL_SPACE,pSpaceRecord,AcDb::kForWrite)) != Acad::eOk)
- {
- pBlockTable->close();
- return es;
- }
- pBlockTable->close();
- if ((es = pSpaceRecord->appendAcDbEntity(objId, ent)) != Acad::eOk)
- { pSpaceRecord->close();
- return es;
- }
- pSpaceRecord->close();
- return ent->close();
- }
- static void Test()
- {
- AcDbHatch* pHatch = new AcDbHatch();
- // Set hatch plane
- AcGeVector3d normal(0.0, 0.0, 1.0);
- pHatch->setNormal(normal);
- pHatch->setElevation(0.0);
- // Set hatch pattern to ANSI31 predefined type //
- pHatch->setPattern(AcDbHatch::kPreDefined, _T("ANSI31"));
- // Set Associativity
- pHatch->setAssociative(Adesk::kTrue);
- // Construct database AcDbLines
- AcGePoint3d vertexPts[4];
- AcDbObjectId lineId, cirId, hatchId;
- AcDbObjectIdArray dbObjIds;
- AcDbLine *line;
- vertexPts[0].set(2.0, 2.0, 0.0);
- vertexPts[1].set(8.0, 2.0, 0.0);
- vertexPts[2].set(8.0, 8.0, 0.0);
- vertexPts[3].set(2.0, 8.0, 0.0);
- for (int i = 0; i < 4; i++)
- {
- line = new AcDbLine();
- line->setStartPoint(vertexPts);
- line->setEndPoint(vertexPts[(i == 3) ? 0 : i+1]);
- postToDb(line, lineId);
- dbObjIds.append(lineId);
- }
- // Append an external rectangular loop to hatch boundary //
- pHatch->appendLoop(AcDbHatch::kExternal, dbObjIds);
- // Create a AcDbCircle and post it to database //
- AcGePoint3d cenPt(5.0, 5.0, 0.0);
- normal.set(0.0, 0.0, 1.0);
- AcDbCircle *circle = new AcDbCircle();
- circle->setNormal(normal);
- circle->setCenter(cenPt);
- circle->setRadius(1.0);
- postToDb(circle, cirId);
- dbObjIds.setLogicalLength(0);
- dbObjIds.append(cirId);
- // Append an internal loop (circle) to hatch boundary //
- pHatch->appendLoop(AcDbHatch::kDefault, dbObjIds);
- // Elaborate hatch lines
- pHatch->evaluateHatch();
- // Get all associative source boundary object Ids for later use. //
- dbObjIds.setLogicalLength(0);
- pHatch->getAssocObjIds(dbObjIds);
- // Post hatch entity to database
- postToDb(pHatch, hatchId);
- // Attach hatchId to all source boundary objects for notification. //
- AcDbEntity *pEnt;
- int numObjs = dbObjIds.length();
- for (int i = 0; i < numObjs; i++)
- {
- if (acdbOpenAcDbEntity(pEnt, dbObjIds,AcDb::kForWrite)==Acad::eOk)
- {
- pEnt->addPersistentReactor(hatchId);
- pEnt->close();
- }
- }
- }
|
|