|
发表于 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;iaddVertexAt(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() booleanOper(AcDb::kBoolIntersect,(AcDbRegion*)regions[i]))
acutPrintf("有问题\n");
delete (AcRxObject*)regions[i];
}
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;
} |
|