- UID
- 134469
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2004-5-7
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
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->setPattern(AcDbHatch::kPreDefined, "ANSI31");
// Set Associativity
//
pHatch->setAssociative(Adesk::kTrue);
// Construct database AcDbLines
//
AcGePoint3d vertexPts[4];
AcDbObjectId lineId, cirId, hatchId;
AcDbObjectIdArray dbObjIds,dbObjId2;
AcDbLine *line;
vertexPts[0].set(2.0, 2.0, 0.0);
vertexPts[1].set(20.0, 2.0, 0.0);
vertexPts[2].set(20.0, 20.0, 0.0);
vertexPts[3].set(2.0, 8.0, 0.0);
int b;
CreateLine(vertexPts[0],vertexPts[1],lineId);
dbObjIds.append(lineId);
CreateLine(vertexPts[1],vertexPts[2],lineId);
dbObjIds.append(lineId);
CreateLine(vertexPts[2],vertexPts[3],lineId);
dbObjIds.append(lineId);
CreateLine(vertexPts[3],vertexPts[0],lineId);
b = dbObjIds.append(lineId);
// Append an external rectangular loop to hatch boundary
//
pHatch->appendLoop(AcDbHatch::kExternal, dbObjIds);
b = pHatch->numLoops();
// Create a AcDbCircle and post it to database
//
AcGePoint3d cenPt(5.0, 5.0, 0.0);
AcDbCircle *circle = new AcDbCircle(cenPt,normal,2);
AcDbBlockTable *pBlockTbale;
Acad::ErrorStatus es = acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTbale, AcDb::kForRead);
if (es != Acad::eOk)
{
//delete pLine;
return es;
}
AcDbBlockTableRecord *pBlockTbaleRecord;
pBlockTbale->getAt(ACDB_MODEL_SPACE, pBlockTbaleRecord, AcDb::kForWrite);
pBlockTbale->close();
es = pBlockTbaleRecord->appendAcDbEntity(cirId, circle);
dbObjIds.setLogicalLength(0);
b = dbObjIds.append(cirId);
b = dbObjIds.length();
// Append an internal loop (circle) to hatch boundary
//
//在调用这里的时候,返回错误, 想问问为什么?
if(Acad::eOk!=pHatch->appendLoop(AcDbHatch::kDefault ,dbObjIds))
{
AfxMessageBox("加入错误");
return Acad::eOk;
}
b = pHatch->numLoops();
// Elaborate hatch lines
//
pHatch->evaluateHatch();
// Get all associative source boundary object Ids for later use.
//
dbObjIds.setLogicalLength(0);
pHatch->getAssocObjIds(dbObjIds);
b = dbObjIds.length();
// Post hatch entity to database
//
//pHatch->postToDb(pHatch, hatchId);
pBlockTbaleRecord->appendAcDbEntity(hatchId, pHatch);
pBlockTbaleRecord->close();
circle->close();
// Attach hatchId to all source boundary objects for notification.
//
AcDbEntity *pEnt;
int numObjs = dbObjIds.length();
//Acad::ErrorStatus es;
for (int i = 0; i < numObjs; i++)
{
es = acdbOpenAcDbEntity(pEnt, dbObjIds, AcDb::kForWrite);
if (es == Acad::eOk)
{
pEnt->addPersistentReactor(hatchId);
pEnt->close();
}
}
return eOk;
} |
|