用顶点表创建REGION

来源:百度文库 编辑:神马文学网 时间:2024/03/28 23:09:32
// 参数AcGePoint3dArray// 用顶点表创建REGION.
AcDbObjectId CreateRegionFromPoints(AcGePoint3dArray InPoints)
{
// 创建polyline.
AcDbObjectId polylineID = NULL;
polylineID = createPolyline(InPoints);
// 打开POLYLINE.
AcDbEntity* pPolyline;
AcDbObjectId regionId;
acdbOpenAcDbEntity(pPolyline, polylineID, AcDb::kForRead);
// 用polyline 创建REGION
AcDbVoidPtrArray polylineArray;
polylineArray.append(static_cast(pPolyline));
AcDbVoidPtrArray regions;
AcDbRegion::createFromCurves(polylineArray, regions);
AcDbRegion *pRegion = NULL;
pRegion = AcDbRegion::cast((AcRxObject*)regions[0]);
pPolyline->close();
// 添加REGION到数据库
AcDbBlockTable* pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord* pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
pBlockTable->close();
AcDbRegion* regionObj = static_cast(regions[0]);
pBlockTableRecord->appendAcDbEntity(regionId, regionObj);
pBlockTableRecord->close();
regionObj->close();
// 返回REGION的ID.
return regionId;
}