我的程序是通过一个对话框,由用户输入数据的位置和需要移到0图层的图层名称,然后“OK”完成批处理将图形的一些图层的数据移到0图层。下面是主要代码,问题还是依旧是那样的(没有出任何错误,但是也没有执行任何操作,包括最后最后从层表中删除图层也没有执行)大家帮忙看看问题出在哪里啊?谢谢 void lcdlg::layerclear() //主函数 { if(cPath=="") cPath= "D:\\temp\\"; //缺省条件下的数据位置 CFileFind find; CFileFind pathfind; BOOL bFileIsFind; CString cDWGPath = cPath+"*.dwg"; bFileIsFind = find.FindFile(cDWGPath); int filecounter=0; AcDbDatabase *pcurdb= new AcDbDatabase(Adesk::kTrue,Adesk::kTrue); pcurdb=acdbHostApplicationServices()->workingDatabase(); CreateDirectory(cPath+"questioned\\",NULL); //生成一个文件名为questioned的文件夹 CreateDirectory(cPath+"OK\\",NULL); //生成一个文件名为OK的文件夹 while (bFileIsFind) { bAllDone=true; AcDbDatabase *preaddb= new AcDbDatabase(Adesk::kFalse,Adesk::kTrue); if(bFileIsFind) { filecounter++; bFileIsFind = find.FindNextFile(); find.GetFileName(); Acad::ErrorStatus es =preaddb->readDwgFile(find.GetFilePath(),_SH_DENYNO); if(es==Acad::eOk) { acdbHostApplicationServices()->setWorkingDatabase(preaddb); clear(preaddb,layernames); if(bAllDone) preaddb->saveAs(cPath+"OK\\"+find.GetFileName()); else preaddb->saveAs(cPath+"questioned\\"+find.GetFileName()); acdbHostApplicationServices()->setWorkingDatabase(pcurdb); delete preaddb; DeleteFile(find.GetFilePath()); } else AfxMessageBox("文件"+find.GetFileName()+"打开出错"); } } CString str; str.Format("%d",filecounter); AfxMessageBox("修改了"+str+"个文件"); } void lcdlg::clear(AcDbDatabase *pdb,char *names) //多个需要更改图层的情况 { AcDbDatabase *pD; AcDbLayerTable *pT; pD=pdb; AcDbObjectIdArray nIDs; char layername[256]; int count1=0; int count2=0; layername[0]=names[0]; while (layername[count1]!='\0') { count2++; if(layername[count1]==';') { while(count1<255) { layername[count1]='\0'; count1++; } pD->getSymbolTable(pT, AcDb::kForRead); if(pT->has(layername)) delSS(layername,nIDs); else bAllDone=false; count1=0; } else count1++; layername[count1]=names[count2]; } } void lcdlg::OnOK() //对象框的OK按钮 { CDialog::OnOK(); sprintf(layernames , "%s",m_layernames); cPath=m_path; layerclear(); } void lcdlg::delSS(char* nLayerName,AcDbObjectIdArray& nIDs)//将一个图层的数据移到0图层
{ Acad::ErrorStatus es = Acad::eOk; ads_name ents; struct resbuf *rb; struct resbuf blc; AcDbEntity *pE; rb=acutNewRb(AcDb::kDxfLayerName); rb->restype=8; rb->resval.rstring=(char*)nLayerName; rb->rbnext=NULL; acedSSGet("X",NULL,NULL,rb,ents); // long entNums=0; long entNums; acedSSLength(ents,&entNums); if (entNums == 0) es = Acad::eInvalidInput; else { for (long a = 0; a < entNums ; a ++) { AcDbObjectId objId; ads_name ent; AcDbObject* obj; acedSSName(ents,a,ent); acdbGetObjectId(objId, ent); acdbOpenObject(pE,objId,AcDb::kForWrite,false); nIDs.append(objId); pE->setLayer("0"); pE->close; obj->close; nIDs.append(objId); } } acedSSFree(ents); blc.restype = RTSTR; blc.resval.rstring = "0"; acedSetVar("CLAYER",&blc);//设置当前图层为0层 AcDbLayerTable * pLayerTbl;//定义层表指针 acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTbl, AcDb::kForWrite); AcDbLayerTableRecord * pLayerTblRcd; //定义层表记录指针 if ( Acad::eOk == pLayerTbl->getAt((char*)nLayerName, pLayerTblRcd , AcDb::kForWrite)) { pLayerTblRcd->erase(true);//删除图层 } pLayerTblRcd->close(); pLayerTbl->close(); acutRelRb(rb); } |