- 积分
- 1665
- 明经币
- 个
- 注册时间
- 2003-3-31
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2004-10-1 23:30:00
|
显示全部楼层
不好意思。我再发一次
void AppmytoolCloReg() { ads_point pt1,pt2,pt; AcGePoint2dArray point_Array; AcDbObjectId IdObj,faceId; AcDbEntity *pEnt=NULL;
AcGePoint3d pA(0,0,0),pB(100,0,0),pC(100,100,0),pD(0,100,0); AcDbFace *pFace=new AcDbFace(pA,pB,pC,pD); postToDatabase(pFace,faceId);
int stat=1; stat=acedGetPoint(NULL,"选择点(ESC结束)\n",pt1); if(stat==RTCAN) return; point_Array.append(asPnt2d(pt1)); while(1) { acdbPointSet(pt1, pt2); stat=acedGetPoint(pt1,"选择点,(ESC结束)\n",pt1); acedGrDraw(pt2, pt1, 1, 0); if(stat==RTCAN) break; point_Array.append(asPnt2d(pt1)); } AcDbPolyline *ClosePolyline=new AcDbPolyline(); for(int i=0;i<point_Array.length();i++) { AcGePoint2d pTmp=point_Array.at(i); ClosePolyline->addVertexAt(i,pTmp,0,-1,-1); }
ClosePolyline->setColorIndex(1); ClosePolyline->setClosed(Adesk::kTrue); postToDatabase(ClosePolyline,IdObj);//添加实体数据库中
acdbOpenAcDbEntity(pEnt,IdObj,AcDb::kForRead); AcDbPolyline *pPoly=AcDbPolyline::cast(pEnt);
AcDbVoidPtrArray entities,regions; entities.append(pFace); entities.append(pPoly); AcDbRegion::createFromCurves(entities, regions); if (regions.length() < 1) { acutPrintf("构造闭合区域错误\n"); } assert(pRegion != NULL); AcDbRegion *pRegion = new AcDbRegion; for ( i = 0; i < regions.length(); i++) { if(Acad::eOk!=pRegion->booleanOper(AcDb::kBoolIntersect,(AcDbRegion*)regions)) acutPrintf("有问题\n"); delete (AcRxObject*)regions; } double regArea; pRegion->getArea(regArea); pRegion->close(); pEnt->close();
acutPrintf("area=%0.3f\n",regArea); }
Acad::ErrorStatus postToDatabase(/*[in]*/AcDbEntity* pEnt,/*[out]*/AcDbObjectId& idObj)
{ Acad::ErrorStatus es; AcDbBlockTable* pBlockTable; AcDbBlockTableRecord* pSpaceRecord; if (acdbHostApplicationServices()->workingDatabase()==NULL) return Acad::eNoDatabase; if ((es = acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead))==Acad::eOk){ if ((es = pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord, AcDb::kForWrite))==Acad::eOk){ if ((es = pSpaceRecord->appendAcDbEntity(idObj, pEnt))==Acad::eOk) pEnt->close(); pSpaceRecord->close(); } pBlockTable->close();
} return es; } |
|