tongtong 发表于 2007-2-9 16:46:00
<p>我的程序是通过一个对话框,由用户输入数据的位置和需要移到0图层的图层名称,然后“OK”完成批处理将图形的一些图层的数据移到0图层。下面是主要代码,问题还是依旧是那样的(没有出任何错误,但是也没有执行任何操作,包括最后最后从层表中删除图层也没有执行)大家帮忙看看问题出在哪里啊?谢谢</p><p>void lcdlg::layerclear() //主函数<br/>{<br/> if(cPath=="")<br/> cPath= "D:\\temp\\"; //缺省条件下的数据位置</p><p> CFileFind find;<br/> CFileFind pathfind;<br/> BOOL bFileIsFind;<br/> CString cDWGPath = cPath+"*.dwg";<br/> bFileIsFind = find.FindFile(cDWGPath);<br/> int filecounter=0;<br/> AcDbDatabase *pcurdb= new AcDbDatabase(Adesk::kTrue,Adesk::kTrue);<br/> pcurdb=acdbHostApplicationServices()->workingDatabase();<br/> CreateDirectory(cPath+"questioned\\",NULL); //生成一个文件名为questioned的文件夹<br/> CreateDirectory(cPath+"OK\\",NULL); //生成一个文件名为OK的文件夹<br/> while (bFileIsFind)<br/> {<br/> bAllDone=true;<br/> AcDbDatabase *preaddb= new AcDbDatabase(Adesk::kFalse,Adesk::kTrue);<br/> if(bFileIsFind)<br/> {<br/> filecounter++;<br/> bFileIsFind = find.FindNextFile();<br/> find.GetFileName();<br/> Acad::ErrorStatus es =preaddb->readDwgFile(find.GetFilePath(),_SH_DENYNO);<br/> if(es==Acad::eOk)<br/> {<br/> acdbHostApplicationServices()->setWorkingDatabase(preaddb);<br/> clear(preaddb,layernames);<br/> if(bAllDone)<br/> preaddb->saveAs(cPath+"OK\\"+find.GetFileName());<br/> else<br/> preaddb->saveAs(cPath+"questioned\\"+find.GetFileName());<br/> acdbHostApplicationServices()->setWorkingDatabase(pcurdb);<br/> delete preaddb;<br/> DeleteFile(find.GetFilePath());<br/> }<br/> else<br/> AfxMessageBox("文件"+find.GetFileName()+"打开出错");<br/> }<br/> }<br/> CString str;<br/> str.Format("%d",filecounter);<br/> AfxMessageBox("修改了"+str+"个文件");</p><p>}</p><p>void lcdlg::clear(AcDbDatabase *pdb,char *names) //多个需要更改图层的情况<br/>{<br/> AcDbDatabase *pD;<br/> AcDbLayerTable *pT;<br/> pD=pdb;<br/> AcDbObjectIdArray nIDs;<br/> char layername;<br/> int count1=0;<br/> int count2=0;<br/> layername=names;<br/> while (layername!='\0')<br/> {<br/> count2++;<br/> if(layername==';')<br/> {<br/> while(count1<255)<br/> {<br/> layername='\0';<br/> count1++;<br/> }<br/> <br/> pD->getSymbolTable(pT, AcDb::kForRead);<br/> if(pT->has(layername))<br/> delSS(layername,nIDs);</p><p> else<br/> bAllDone=false;<br/> count1=0;<br/> }<br/> else<br/> count1++;<br/> layername=names;<br/> }<br/>}</p><p>void lcdlg::OnOK() //对象框的OK按钮<br/>{<br/> CDialog::OnOK();<br/> sprintf(layernames , "%s",m_layernames);<br/> cPath=m_path;<br/> layerclear();<br/>}</p><p>void lcdlg::delSS(char* nLayerName,AcDbObjectIdArray& nIDs)//将一个图层的数据移到0图层<br/><br/>{<br/> Acad::ErrorStatus es = Acad::eOk;<br/> ads_name ents;<br/> struct resbuf *rb;<br/> struct resbuf blc;<br/> AcDbEntity *pE;</p><p> rb=acutNewRb(AcDb::kDxfLayerName);<br/> rb->restype=8;<br/> rb->resval.rstring=(char*)nLayerName;<br/> rb->rbnext=NULL;<br/> acedSSGet("X",NULL,NULL,rb,ents);</p><p>// long entNums=0;<br/> long entNums;</p><p> acedSSLength(ents,&entNums);<br/> if (entNums == 0)<br/> es = Acad::eInvalidInput;<br/> else<br/> {<br/> for (long a = 0; a < entNums ; a ++)<br/> {<br/> AcDbObjectId objId;<br/> ads_name ent;<br/> AcDbObject* obj;<br/> <br/> acedSSName(ents,a,ent);<br/> acdbGetObjectId(objId, ent);<br/> acdbOpenObject(pE,objId,AcDb::kForWrite,false);<br/> nIDs.append(objId);</p><p> pE->setLayer("0");<br/> pE->close;<br/> obj->close;<br/> nIDs.append(objId);<br/> }<br/> }<br/> acedSSFree(ents);<br/> blc.restype = RTSTR;<br/> blc.resval.rstring = "0";<br/> acedSetVar("CLAYER",&blc);//设置当前图层为0层 </p><p> AcDbLayerTable * pLayerTbl;//定义层表指针<br/> acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTbl, AcDb::kForWrite);<br/> <br/> AcDbLayerTableRecord * pLayerTblRcd; //定义层表记录指针<br/> if ( Acad::eOk == pLayerTbl->getAt((char*)nLayerName, pLayerTblRcd , AcDb::kForWrite))<br/> {<br/> pLayerTblRcd->erase(true);//删除图层<br/> } <br/> pLayerTblRcd->close(); <br/> pLayerTbl->close();<br/> acutRelRb(rb);<br/>}</p>tongtong 发表于 2007-2-12 08:53:00
<p>按照上面的方法现在出现错误提示“Error writting/closing file”,然后把我的测试数据全删掉拉。这是什么问题?</p>tongtong 发表于 2007-2-12 11:19:00
<p>好的,谢谢大家,已经调试好了。至于上面出错原因我还是不清楚。现将将成功代码公布如下:</p><p>void lcdlg::layerclear() //主函数<br/>{<br/> if(cPath=="")<br/> cPath= "D:\\temp\\"; //缺省条件下的数据位置</p><p> CFileFind find;<br/> CFileFind pathfind;<br/> BOOL bFileIsFind;<br/> CString cDWGPath = cPath+"*.dwg";<br/> bFileIsFind = find.FindFile(cDWGPath);<br/> int filecounter=0;<br/> AcDbDatabase *pcurdb= new AcDbDatabase(Adesk::kTrue,Adesk::kTrue);<br/> pcurdb=acdbHostApplicationServices()->workingDatabase();<br/> CreateDirectory(cPath+"questioned\\",NULL); //生成一个文件名为questioned的文件夹<br/> CreateDirectory(cPath+"OK\\",NULL); //生成一个文件名为OK的文件夹<br/> while (bFileIsFind)<br/> {<br/> bAllDone=true;<br/> AcDbDatabase *preaddb= new AcDbDatabase(Adesk::kFalse,Adesk::kTrue);<br/> if(bFileIsFind)<br/> {<br/> filecounter++;<br/> bFileIsFind = find.FindNextFile();<br/> find.GetFileName();<br/> Acad::ErrorStatus es =preaddb->readDwgFile(find.GetFilePath(),_SH_DENYNO);<br/> if(es==Acad::eOk)<br/> {<br/> acdbHostApplicationServices()->setWorkingDatabase(preaddb);<br/> clear(preaddb,layernames);<br/> if(bAllDone)<br/> preaddb->saveAs(cPath+"OK\\"+find.GetFileName());<br/> else<br/> preaddb->saveAs(cPath+"questioned\\"+find.GetFileName());<br/> acdbHostApplicationServices()->setWorkingDatabase(pcurdb);<br/> delete preaddb;<br/> DeleteFile(find.GetFilePath());<br/> }<br/> else<br/> AfxMessageBox("文件"+find.GetFileName()+"打开出错");<br/> }<br/> }<br/> CString str;<br/> str.Format("%d",filecounter);<br/> AfxMessageBox("修改了"+str+"个文件");</p><p>}</p><p>void lcdlg::clear(AcDbDatabase *pdb,char *names) //多个需要更改图层的情况<br/>{<br/> AcDbDatabase *pD;<br/> AcDbLayerTable *pT;<br/> pD=pdb;<br/> AcDbObjectIdArray nIDs;<br/> char layername;<br/> int count1=0;<br/> int count2=0;<br/> layername=names;<br/> while (layername!='\0')<br/> {<br/> count2++;<br/> if(layername==';')<br/> {<br/> while(count1<255)<br/> {<br/> layername='\0';<br/> count1++;<br/> }<br/> <br/> pD->getSymbolTable(pT, AcDb::kForRead);<br/> if(pT->has(layername))<br/> delSS(layername); </p><p> else<br/> bAllDone=false;<br/> count1=0;<br/> }<br/> else<br/> count1++;<br/> layername=names;<br/> }<br/>}</p><p>void lcdlg::OnOK() //对象框的OK按钮<br/>{<br/> CDialog::OnOK();<br/> sprintf(layernames , "%s",m_layernames);<br/> cPath=m_path;<br/> layerclear();<br/>}</p><p>void lcdlg::delSS(const char *sLay)<br/>{<br/> ads_name ss;<br/> struct resbuf *rb=acutBuildList(8,sLay,NULL);<br/> long nLen=0;<br/> if(acedSSGet("X",NULL,NULL,rb,ss)!=RTNORM)<br/> {<br/> acutRelRb(rb);<br/> return;<br/> }<br/> acutRelRb(rb);</p><p> acedSSLength(ss,&nLen);<br/> for(long n=0L;n<nLen;n++)<br/> {<br/> ads_name ent;<br/> acedSSName(ss,n,ent);<br/> AcDbObjectId idEnt;<br/> acdbGetObjectId(idEnt,ent);<br/> AcDbEntity *pEnt=NULL;<br/> if(acdbOpenObject(pEnt,idEnt,AcDb::kForWrite)==Acad::eOk)<br/> {<br/> pEnt->setLayer("0");<br/> pEnt->close();<br/> }<br/> }<br/> acedSSFree(ss);<br/>}</p>tongtong 发表于 2007-2-28 10:36:00
<p>如果我还想继续把已经移到0层的图层删除是怎么做的啊?我是这样做的,但是有问题,请指教</p><p>void lcdlg::delSS(const char *sLay)<br/>{<br/> ads_name ss;<br/> struct resbuf *rb=acutBuildList(8,sLay,NULL);<br/> long nLen=0;<br/> if(acedSSGet("X",NULL,NULL,rb,ss)!=RTNORM)<br/> {<br/> acutRelRb(rb);<br/> return;<br/> }<br/> acutRelRb(rb);</p><p> acedSSLength(ss,&nLen);<br/> for(long n=0L;n<nLen;n++)<br/> {<br/> ads_name ent;<br/> acedSSName(ss,n,ent);<br/> AcDbObjectId idEnt;<br/> acdbGetObjectId(idEnt,ent);<br/> AcDbEntity *pEnt=NULL;<br/> if(acdbOpenObject(pEnt,idEnt,AcDb::kForWrite)==Acad::eOk)<br/> {<br/> pEnt->setLayer("0");<br/> pEnt->close();<br/> }<br/> }<br/> acedSSFree(ss);</p><p> <br/> <font color="#ff3300">AcDbLayerTable * pLayerTbl;//定义层表指针<br/> acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTbl, AcDb::kForWrite);<br/> <br/> AcDbLayerTableRecord * pLayerTblRcd; //定义层表记录指针<br/> if ( Acad::eOk == pLayerTbl->getAt(sLay, pLayerTblRcd , AcDb::kForWrite))<br/> {<br/> pLayerTblRcd->erase(true);//删除图层<br/> } <br/> pLayerTblRcd->close(); <br/> pLayerTbl->close();<br/> free(&sLay);<br/></font> <br/>}<br/></p>
页:
1
[2]