- UID
- 3684
- 积分
- 844
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-4-8
- 最后登录
- 1970-1-1
|
发表于 2005-1-9 23:12:30
|
显示全部楼层
源自帮助
The following example shows how to acquire an associative hatch entity on the WCS XY plane. The hatch boundary consists of an external rectangular loop with an internal circular hole. The hatch pattern is the ANSI31 predefined type with current AutoCAD default color. The newly created hatch is associative, in which you can change the source boundary geometry to update the hatch pattern.
Acad::ErrorStatus acqHatch2()
{
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->setHatchPattern(AcDbHatch::kPreDefined, "ANSI31");
// Set Associativity
//
pHatch->setAssociative(Adesk::kTrue);
// Construct database AcDbLines
//
AcGePoint2d 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])
line->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
//
AcGePoint2d cenPt(5.0, 5.0, 0.0);
AcGeVector3d normal(0.0, 0.0, 1.0);
AcDbCircle *circle = new AcDbCircle();
circle->setNormal(normal);
circle->setCenter(cenPt);
circle->setRadius(1.0);
circle->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
//
pHatch->postToDb(pHatch, hatchId);
// Attach hatchId to all source boundary objects for notification.
//
AcDbEntity *pEnt;
int numObjs = dbObjIds.length();
Acad::ErrorStatus es;
for (i = 0; i < numObjs; i++) {
es = acdbOpenAcDbEntity(pEnt, dbObjIds, AcDb::kForWrite);
if (es == Acad::eOk) {
pEnt->addPersistentReactor(hatchId);
pEnt->close();
}
}
return eOk;
} |
|