[分享]遍历块表记录
摘自《AutoCAD ObjectARX2000开发技术指南》我们用下面的例子说明如何使用块表记录遍历器遍历块表记录,并在屏幕上打印出块中所含对象的信息。<BR> 程序中用printAll()函数打开一个块表进行读操作,然后根据用户提供的块名打开块表记录,使用一个新块表记录遍历器遍历块表记录。如果记录中含有实体,则遍历器打印出该实体的信息<BR> void<BR> printAll()<BR> {<BR> int rc;<BR> char blkName;<BR> rc = acedGetString(Adesk::kTrue,<BR> "请输入块名<回车取回当前空间块名>:",<BR> blkName);<BR> if(rc!=RTNORM)<BR> return;<BR> if(blkName=='\0'){<BR> if(acdbHostApplicationServices()->workingDatabase()<BR> ->tilemode() == Adesk::kFalse){<BR> struct resbuf rb;<BR> acedGetVar("cvport",&rb);<BR> if(rb.resval.rint == 1){<BR> strcpy(blkName,ACDB_PAPER_SPACE);<BR> }else{<BR> strcpy(blkName,ACDB_MODEL_SPACE);<BR> }<BR> }else{<BR> strcpy(blkName,ACDB_MODEL_SPACE);<BR> }<BR> }<BR> AcDbBlockTable* pBlockTable;<BR> acdbHostApplicationServices()->workingDatabase()<BR> ->getSymbolTable(pBlockTable,AcDb::kForRead);<BR> AcDbBlockTableRecord *pBlockTableRecord;<BR> pBlockTable->getAt(blkName,pBlockTableRecord,<BR> AcDb::kForRead);<BR> <BR> AcDbBlockTableRecordIterator *pBlockIterator;<BR> pBlockTableRecord ->newIterator(pBlockIterator);<BR> for(;!pBlockIterator->done();<BR> pBlockIterator->step())<BR> {<BR> AcDbEntity *pEntity;<BR> pBlockIterator->getEntity(pEntity,AcDb::kForRead);<BR> AcDbHandle objHandle;<BR> pEntity->getAcDbHandle(objHandle);<BR> char handleStr;<BR> objHandle.getIntoAsciiBuffer(handkeStr);<BR> const char *pCname = pEntity->isA()->name();<BR> acutPrintf("对象ID%lx,名柄%s,类名%s.\n",<BR> pEntity->objId(),handleStr,pCname);<BR> pEntity->close();<BR> }<BR> delete pBlockIterator;<BR> pBlockTableRecord->close();<BR> acutPrintf("\n");<BR> }<BR>
页:
[1]