AcDbFace面域问题??????
我问过这个问题了,但是还不明白。请版主帮忙解释一下:一下是我的做法,不知道为什么求不出面积。
AcGePoint3d pA(0,0,0),pB(100,0,0),pC(100,100,0),pD(0,100,0);<BR>AcDbFace *pFace=new AcDbFace(pA,pB,pC,pD);<BR>postToDatabase(pFace,faceId);
ads_point pt1,pt2,pt;<BR>AcGePoint2dArray point_Array;
int stat=1;<BR> stat=acedGetPoint(NULL,"选择点(ESC结束)\n",pt1);<BR> if(stat==RTCAN)<BR> return;<BR> point_Array.append(asPnt2d(pt1));<BR> while(1)<BR> {<BR> acdbPointSet(pt1, pt2);<BR> <A href="file://stat/" target="_blank" >file://stat</A> = acedGetPoint(pick, "选择下一点(ESC-quit): ", pick);<BR> stat=acedGetPoint(pt1,"选择点,(ESC结束)\n",pt1);<BR> acedGrDraw(pt2, pt1, 1, 0);<BR> if(stat==RTCAN)<BR> break;<BR> point_Array.append(asPnt2d(pt1));<BR> }<BR> AcDbPolyline *ClosePolyline=new AcDbPolyline();<BR> for(int i=0;i<point_Array.length();i++)<BR> {<BR> AcGePoint2d pTmp=point_Array.at(i);<BR> ClosePolyline->addVertexAt(i,pTmp,0,-1,-1);<BR> }
ClosePolyline->setColorIndex(1);<BR> ClosePolyline->setClosed(Adesk::kTrue);<BR> postToDatabase(ClosePolyline,IdObj);<BR> acdbOpenAcDbEntity(pEnt,IdObj,AcDb::kForRead);<BR> AcDbPolyline *pPoly=AcDbPolyline::cast(pEnt);
<BR> AcDbVoidPtrArray entities,regions;<BR> entities.append(pFace);<BR> entities.append(pPoly);<BR> AcDbRegion::createFromCurves(entities, regions);<BR> if (regions.length() < 1) <BR> {<BR> acutPrintf("构造闭合区域错误\n");<BR> }<BR> assert(pRegion != NULL);<BR> AcDbRegion *pRegion = new AcDbRegion;<BR> <BR> for ( i = 0; i < regions.length(); i++)<BR> {<BR> if(Acad::eOk!=pReg->booleanOper(AcDb::kBoolIntersect,(AcDbRegion*) regions))<BR> acutPrintf("有问题\n");<BR> delete (AcRxObject*)regions;<BR> <BR> }<BR> double regArea;<BR> pReg->getArea(regArea);<BR> pReg->close();<BR> acutPrintf("area=%0.3f\n",regArea);
请高手指出错误。
回复
能贴出你完整的代码吗?没做过,只能帮你调试一下了. 上面基本的程序放到一个函数里面即可。
版主可以看看<A href="http://bbs.mjtd.com/forum.php?mod=viewthread&tid=26604" target="_blank" >两个多边形相交,如何求两个图形的交集的面积??</A> 帖子,
告诉我做法了,但是我没有求出结果。
基本思想。就是两个实体(闭合的)然后求出图形交集部分的面积
回复
这里<A href="file://stat/" target=_blank><FONT color=#000000>file://stat</FONT></A> = acedGetPoint(pick, "选择下一点(ESC-quit): ", pick);<BR> stat=acedGetPoint(pt1,"选择点,(ESC结束)\n",pt1);
是什么? file:这一行需要吗?
postToDatabase也是未声明的?
很多未声明的标识符!
那是注释掉得语句。粘贴到帖子上就加了file。不要。
postToDatabase()是把该实体添加到图形数据库中
回复
没法调试, 这段代码中很多变量都是没有声明的.postToDatabase
IdObj
pEnt
pRegion
pReg
...
因为我没做过,所以看不出应该怎么改.
postToDatabase是个自定义的函数
Acad::ErrorStatus postToDatabase(AcDbEntity* ent, AcDbObjectId& objId)<BR>{<BR> // Given an entity, this function will post it to the database<BR> // in MODEL_SPACE and then return the objectId; returns eOk if<BR> // all went well.<BR> <BR> Acad::ErrorStatus es;<BR> AcDbBlockTable* pBlockTable;<BR> AcDbBlockTableRecord* pSpaceRecord;<BR> <BR> es = acdbHostApplicationServices()->workingDatabase()<BR> ->getSymbolTable(pBlockTable, AcDb::kForRead);
assert(es == Acad::eOk);<BR> <BR> es = pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord, AcDb::kForWrite);<BR> assert(es == Acad::eOk);<BR> <BR> es = pBlockTable->close();<BR> assert(es == Acad::eOk);<BR> <BR> es = pSpaceRecord->appendAcDbEntity(objId, ent);<BR> assert(es == Acad::eOk);<BR> <BR> es = ent->close();<BR> assert(es == Acad::eOk);<BR> <BR> es = pSpaceRecord->close();<BR> assert(es == Acad::eOk);<BR> <BR> return es;<BR>} 不好意思。我再发一次
void AppmytoolCloReg()<BR>{<BR> ads_point pt1,pt2,pt;<BR> AcGePoint2dArray point_Array;<BR> AcDbObjectId IdObj,faceId;<BR> AcDbEntity *pEnt=NULL;
<BR> AcGePoint3d pA(0,0,0),pB(100,0,0),pC(100,100,0),pD(0,100,0);<BR> AcDbFace *pFace=new AcDbFace(pA,pB,pC,pD);<BR> postToDatabase(pFace,faceId);
int stat=1;<BR> stat=acedGetPoint(NULL,"选择点(ESC结束)\n",pt1);<BR> if(stat==RTCAN)<BR> return;<BR> point_Array.append(asPnt2d(pt1));<BR> while(1)<BR> {<BR> acdbPointSet(pt1, pt2);<BR> stat=acedGetPoint(pt1,"选择点,(ESC结束)\n",pt1);<BR> acedGrDraw(pt2, pt1, 1, 0);<BR> if(stat==RTCAN)<BR> break;<BR> point_Array.append(asPnt2d(pt1));<BR> }<BR> AcDbPolyline *ClosePolyline=new AcDbPolyline();<BR> for(int i=0;i<point_Array.length();i++)<BR> {<BR> AcGePoint2d pTmp=point_Array.at(i);<BR> ClosePolyline->addVertexAt(i,pTmp,0,-1,-1);<BR> }
ClosePolyline->setColorIndex(1);<BR> ClosePolyline->setClosed(Adesk::kTrue);<BR> postToDatabase(ClosePolyline,IdObj);//添加实体数据库中
acdbOpenAcDbEntity(pEnt,IdObj,AcDb::kForRead);<BR> AcDbPolyline *pPoly=AcDbPolyline::cast(pEnt);
AcDbVoidPtrArray entities,regions;<BR> entities.append(pFace);<BR> entities.append(pPoly);<BR> AcDbRegion::createFromCurves(entities, regions);<BR> if (regions.length() < 1) <BR> {<BR> acutPrintf("构造闭合区域错误\n");<BR> }<BR> assert(pRegion != NULL);<BR> AcDbRegion *pRegion = new AcDbRegion;<BR> <BR> for ( i = 0; i < regions.length(); i++)<BR> {<BR> <BR> if(Acad::eOk!=pRegion->booleanOper(AcDb::kBoolIntersect,(AcDbRegion*)regions))<BR> acutPrintf("有问题\n");<BR> delete (AcRxObject*)regions;<BR> <BR> }<BR> double regArea;<BR> pRegion->getArea(regArea);<BR> pRegion->close();<BR> pEnt->close();
acutPrintf("area=%0.3f\n",regArea); <BR>}
Acad::ErrorStatus <BR>postToDatabase(/**/AcDbEntity* pEnt,/**/AcDbObjectId& idObj)
{<BR> Acad::ErrorStatus es;<BR> AcDbBlockTable* pBlockTable;<BR> AcDbBlockTableRecord* pSpaceRecord;<BR> <BR> if (acdbHostApplicationServices()->workingDatabase()==NULL)<BR> return Acad::eNoDatabase;<BR> <BR> <BR> if ((es = acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead))==Acad::eOk){<BR> <BR> <BR> if ((es = pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord, AcDb::kForWrite))==Acad::eOk){<BR> <BR> <BR> if ((es = pSpaceRecord->appendAcDbEntity(idObj, pEnt))==Acad::eOk)<BR> pEnt->close();<BR> pSpaceRecord->close();<BR> }<BR> pBlockTable->close();
}<BR>return es;<BR>} 先求交点,再创建一个新的面或多线段,面积就出来了
页:
[1]