dipenghao 发表于 2004-10-1 20:49:00

AcDbFace面域问题??????

我问过这个问题了,但是还不明白。请版主帮忙解释一下:
一下是我的做法,不知道为什么求不出面积。
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);
        ads_point pt1,pt2,pt;
AcGePoint2dArray point_Array;
int stat=1;
       stat=acedGetPoint(NULL,"选择点(ESC结束)\n",pt1);
       if(stat==RTCAN)
               return;
                                               point_Array.append(asPnt2d(pt1));
       while(1)
       {
                       acdbPointSet(pt1, pt2);
                                                          = acedGetPoint(pick, "选择下一点(ESC-quit): ", pick);
                                                               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))
                                       acutPrintf("有问题\n");
                                       delete (AcRxObject*)regions;
                       
                               }
                                                                                                                      double regArea;
                                               pReg->getArea(regArea);
                                               pReg->close();
                                               acutPrintf("area=%0.3f\n",regArea);       
请高手指出错误。**** Hidden Message *****

王咣生 发表于 2004-10-1 22:08:00

能贴出你完整的代码吗?
没做过,只能帮你调试一下了.

dipenghao 发表于 2004-10-1 22:27:00

上面基本的程序放到一个函数里面即可。
版主可以看看                        帖子,
告诉我做法了,但是我没有求出结果。
基本思想。就是两个实体(闭合的)然后求出图形交集部分的面积

王咣生 发表于 2004-10-1 22:54:00

这里                                                        file://stat = acedGetPoint(pick, "选择下一点(ESC-quit): ", pick);
                                                               stat=acedGetPoint(pt1,"选择点,(ESC结束)\n",pt1);
是什么?       file:这一行需要吗?
postToDatabase也是未声明的?
很多未声明的标识符!

dipenghao 发表于 2004-10-1 23:02:00

那是注释掉得语句。粘贴到帖子上就加了file。不要。
postToDatabase()是把该实体添加到图形数据库中

王咣生 发表于 2004-10-1 23:10:00

没法调试, 这段代码中很多变量都是没有声明的. postToDatabase
IdObj
pEnt
pRegion
pReg
...
因为我没做过,所以看不出应该怎么改.
postToDatabase是个自定义的函数
Acad::ErrorStatus postToDatabase(AcDbEntity* ent, AcDbObjectId& objId)
{
                       //       Given an entity, this function will post it to the database
                       //       in MODEL_SPACE and then return the objectId;       returns eOk if
                       //       all went well.
                       
                       Acad::ErrorStatus               es;
                       AcDbBlockTable*                pBlockTable;
                       AcDbBlockTableRecord*       pSpaceRecord;
                       
                       es = acdbHostApplicationServices()->workingDatabase()
                                                       ->getSymbolTable(pBlockTable, AcDb::kForRead);
                       assert(es == Acad::eOk);
                       
                       es = pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord, AcDb::kForWrite);
                       assert(es == Acad::eOk);
                       
                       es = pBlockTable->close();
                       assert(es == Acad::eOk);
                       
                       es = pSpaceRecord->appendAcDbEntity(objId, ent);
                       assert(es == Acad::eOk);
                       
                       es = ent->close();
                       assert(es == Acad::eOk);
                       
                       es = pSpaceRecord->close();
                       assert(es == Acad::eOk);
                       
                       return es;
}

dipenghao 发表于 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))
                                       acutPrintf("有问题\n");
                                       delete (AcRxObject*)regions;
                       
                               }
                                                                                                                      double regArea;
                                               pRegion->getArea(regArea);
                                               pRegion->close();
                                pEnt->close();
                                               acutPrintf("area=%0.3f\n",regArea);       
}
Acad::ErrorStatus
postToDatabase(/**/AcDbEntity* pEnt,/**/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;
}

hchdown 发表于 2008-9-22 17:39:00

先求交点,再创建一个新的面或多线段,面积就出来了
页: [1]
查看完整版本: AcDbFace面域问题??????