找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 916|回复: 0

[ARX程序]:作业。。遍历dwg文件所有实体 我做的老有错误。高手帮忙

[复制链接]
发表于 2005-6-2 17:50:06 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
void initApp();
void unloadApp();
void FirstARX();

void initApp()
{
        acedRegCmds->addCommand("FirstARX_Commands","FirstARX","第一次",ACRX_CMD_TRANSPARENT,FirstARX);

}
void unloadApp()
{
        acedRegCmds->removeGroup("FirstARX_Commands");
}
void FirstARX()
{
        ads_alert("HELLO!按确定你将看到这个文件中的实体(包括多段线,圆弧,直线,等等)所属的类名的一个输出.");

    fstream iofile;
        iofile.open("g://record.txt",ios::in|ios::out);
   

       


    AcDbDatabase *pDb=new AcDbDatabase(Adesk::kFalse);
    pDb->readDwgFile("g:\\test.dwg");
        AcDbBlockTable *pBlkTbl;
        pDb->getSymbolTable(pBlkTbl,AcDb::kForRead);
        AcDbBlockTableRecord *pBlkTblRcd;
        pBlkTbl->getAt(ACDB_MODEL_SPACE,pBlkTblRcd,AcDb::kForRead);
        pBlkTbl->close();
        AcDbBlockTableRecordIterator *pBlkTblRcdItr;
        pBlkTblRcd->newIterator(pBlkTblRcdItr);
        AcDbEntity *pEnt;
        for(pBlkTblRcdItr->start();!pBlkTblRcdItr->done();pBlkTblRcdItr->step()){
               
                  pBlkTblRcdItr->getEntity(pEnt,AcDb::kForRead);
         ///////////////////////////////////////////////////////////////////////////////////////////
                  int numPaths,i;
                  AcDbFullSubentPath subentPath;
                  int array[4][4],array1[4][4];
                  int point[3],result[3];                 
                  if(!(ads_trans((1,0,0),2,0,1,result)==RTNORM))exit(0);
                   for(i=0;i<3;i++){
                          array[0]=result;
                          
                  }
                  array[0][3]=0;
                  if(!(ads_trans((0,1,0),2,0,1,result)==RTNORM))exit(0);
                   for(i=0;i<3;i++){
                          array[1]=result;
                          
                  }
                  array[1][3]=0;
                  if(!(ads_trans((0,1,0),2,0,1,result)==RTNORM))exit(0);
                   for(i=0;i<3;i++){
                          array[2]=result;
                          
                  }
                  array[2][3]=0;
                  //以上这些代码是为了产生getSubentPathsAtGsMarker()中的ads_point result这个参数
                  //////////////////////////////////////////////////////////////////////////////
                  if(!(acedSSNameX(,,)==RTNORM))exit(0);
                  ads_name ss ;
                  struct resbuf rbpp;
                  rbpp.restype=0;rbpp.resval.rstring="ATTDEF";rbpp.rbnext=NULL;
                  int            acedSSNameX (struct resbuf **rbpp, const ads_name ss,
                              const long i);
                  
                  int            acedSSGet ("X", NULL,
                            NULL, &rbpp,
                            ss);




                  getSubentPathsAtGsMarker(AcDb::kEdgeSubentType,,,array,numPaths,subentPath);
                 // pEnt->subentPtr(subentPath);这个函数的返回值是指向具体的AcDbCurve的子类型,包括line,circle,arc 等等的指针


                  acutPrintf("classname:%s\n",(pEnt->isA())->name());
                   AcGePoint3d *pt;
                  if((pEnt->isA())->name()=="AcDbLine"){
                         iofile<<(pEnt->subentPtr(subentPath))->name()<<": startPoint&endPoint";
                       
                        pt=(pEnt->subentPtr(subentPath))->startPoint();
                         iofile<<"("<<pt->x<<","<<pt->y<<")";
                         pt=(pEnt->subentPtr(subentPath))->endPoint();
                        iofile<<"("<<pt->x<<","<<pt->y<<")"<<endl;
                  }
                  else if((pEnt->isA())->name()=="AcDbArc"){
                iofile<<(pEnt->isA())->name()<<": center&radius&startAngle&endAngle";
                               
                                pt=(pEnt->subentPtr(subentPath))->center();
                                 iofile<<"("<<pt->x<<","<<pt->y<<")";
                       
                                 iofile<<(pEnt->subentPtr(subentPath))->radius()<<",";
                       
                                iofile<<(pEnt->subentPtr(subentPath))->startAngle()<<",";
                               
                                iofile<<(pEnt->subentPtr(subentPath))->endAngle()<<endl;
                  }
                  else if((pEnt->isA())->name()=="AcDbCircle"){
                          iofile<<(pEnt->isA())->name()<<": center&radius";
                                  pt=(pEnt->subentPtr(subentPath))->center();
                                 iofile<<"("<<pt->x<<","<<pt->y<<")";
                       
                                 iofile<<(pEnt->subentPtr(subentPath))->radius()<<endl;
                  }
                  else if((pEnt->isA())->name()=="AcDbPolyline"){
                          iofile<<(pEnt->isA())->name()<<": AcDbPolyline's vertexes are as follows";
                          AcDbObjectIterator *pvertexIterator=(pEnt->subentPtr(subentPath))->vertexIterator();
                          for(pvertexIterator->start();!pvertexIterator->done();pvertexIterator->step()){

                  (pEnt->subentPtr(subentPath))->openVertex(pt,pvertexIterator->objectId,AcDb::kForRead);
                                  
                                    iofile<<"("<<pt->x<<","<<pt->y<<")";
                          }
                          iofile<<endl;
              delete pvertexIterator;
                  }
                  else if((pEnt->isA())->name()=="AcDbSpline"){
                          int conNum,fitNum,index;

                          if((pEnt->subentPtr(subentPath))->hasFitData()==Adesk::kTrue){
                            fitNum=(pEnt->subentPtr(subentPath))->numFitPoints();
                                    
                          
                            iofile<<(pEnt->isA())->name()<<": AcDbSpline's fitPoints are as follows";
                          
                            for(index=0;index<fitNum;index++){
                                  (pEnt->subentPtr(subentPath))->getFitPointAt(index,pt);
                                   iofile<<"("<<pt->x<<","<<pt->y<<")";
                                }
                          }
                          iofile<<"   and    ";
                          
                          iofile<<(pEnt->isA())->name()<<": AcDbSpline's controlPoints are as follows";
                            for(index=0;index<conNum;index++){
                                    (pEnt->subentPtr(subentPath))->getControlPointAt(index,pt);
                                        iofile<<"("<<pt->x<<","<<pt->y<<")";
                                }
                          iofile<<endl;
                  }
                          




                          








           
                         
                  
                  
                  
                  //这里还可以增加对这些实体进行处理的代码。这里只是简单的把这些实体所属的类的名称给输出一下。
                  iofile.close();
                  
        }
        pEnt->close();
        pBlkTblRcd->close();
        delete pBlkTblRcdItr;
        delete pDb;
}
       
       
       
       
       
       
       
       
        extern "C"AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg,void* pkt)
{
    switch(msg)
        {       
        case AcRx::kInitAppMsg:
                    acrxDynamicLinker->unlockApplication(pkt);
                    initApp();
                    break;
                case AcRx::kUnloadAppMsg:
                        unloadApp();
                        break;
                default:break;
        }
    return AcRx::kRetOK;
}

AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead);

AcDbBlockTableRecord *pBlockRec;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockRec, AcDb::kForWrite);
pBlockTable->close();
AcDbBlockTableRecordIterator* pIter;
pBlockRec->newIterator(pIter);
pBlockRec->close();

for (pIter->start(); !pIter->done(); pIter->step())
{
AcDbEntity *pEnt;
if (pIter->getEntity(pEnt, AcDb::kForRead)!= Acad::eOk)
continue;

if(pEnt->isKindOf(AcDbLine::desc()))
{
AcDbLine *p=(AcDbLine *)pEnt;
acutPrintf("\n长度:%.2lf",p->endPoint());



请高手指点。。最好能发我个源码给我看看(tel:13564162766紧急。老师让周4交。。)。。当然指点1、2也是好的
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-5-10 08:25 , Processed in 0.336107 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表