请教我这段代码,从数据库中读取DWG文件 如何获得AcDbMText坐标
//创建一个空白的图形数据库<BR> //注意该处AcDbDatabase()函数的参数必须为Adesk::kFalse<BR> AcDbDatabase *pNewDb =new AcDbDatabase(Adesk::kFalse);<BR> //将指定文件名的图形A件读入到空白的B形数据库中<BR> const char* sFileName="c:\\AA.dwg";<BR> <BR> Acad::ErrorStatus es=pNewDb->readDwgFile(sFileName , _SH_DENYNO,false); <BR> if (es!=Acad::eOk) <BR> { <BR> acutPrintf("\nThe file %s cannot be opend",sFileName); <BR> return; <BR> } <BR> <BR> //获得块表指针<BR> AcDbBlockTable *pBlockTable; <BR> pNewDb->getSymbolTable(pBlockTable, AcDb::kForRead); <BR> //获得模型空间的块农记录指针<BR> AcDbBlockTableRecord *pBlockTableRecord; <BR> pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForRead); <BR> pBlockTable->close();<BR> //生成块表的迭代器<BR> AcDbBlockTableRecordIterator *pIterator; <BR> pBlockTableRecord->newIterator(pIterator); <BR> <BR> AcGePoint3d basePoint; <BR> AcDbEntity *pEnt; <BR> AcDbMText *pAttdef; <BR> char temp;<BR> int i;<BR> i=0;<BR> for (pIterator->start(); !pIterator->done(); <BR> pIterator->step())//将source.dwg中所有的Attibute进行遍历 <BR> { <BR> i++;<BR> itoa(i,temp,10);///<BR> // acutPrintf(temp);<BR> pIterator->getEntity(pEnt, AcDb::kForRead); <BR> if (pEnt->isKindOf(AcDbMText::desc()))<BR> {<BR> // acutPrintf("第% AcDbMText ",i);<BR> // acutPrintf("\n\n");<BR> pAttdef = AcDbMText::cast(pEnt); <BR> if ( !( pAttdef->contents()==NULL) )<BR> {<BR> acutPrintf(" AcDbMText: %s \n" ,pAttdef->contents());<BR> 获取坐标<BR> // basePoint = pAttdef->position();<BR> // acutPrintf(" AcDbMText: %Ld %Ld %Ld\n" <BR> // ,basePoint->X(),basePoint->Y(),basePoint->Z());<BR> }<BR> }<BR> pEnt->close(); // use pEnt... pAttdef might be NULL <BR> }; <BR> delete pIterator; <BR>} 你的问题是??AcDbMText *pAttdef;往下放,放在你需要的地方,并且你一旦不需要马上关闭. <b>谢谢 我想请问如何获得AcDbMText坐标?</b>
<b></b><BR> pAttdef->location()不是坐标吗? 谢谢 两位 最后可以执行的代码。 <BR> //创建一个空白的图形数据库<BR> //注意该处AcDbDatabase()函数的参数必须为Adesk::kFalse<BR> AcDbDatabase *pNewDb =new AcDbDatabase(Adesk::kFalse);<BR> //将指定文件名的图形A件读入到空白的B形数据库中<BR> const char* sFileName="c:\\AA.dwg";<BR> <BR> Acad::ErrorStatus es=pNewDb->readDwgFile(sFileName , _SH_DENYNO,false); <BR> if (es!=Acad::eOk) <BR> { <BR> acutPrintf("\nThe file %s cannot be opend",sFileName); <BR> return; <BR> } <BR> <BR> //获得块表指针<BR> AcDbBlockTable *pBlockTable; <BR> pNewDb->getSymbolTable(pBlockTable, AcDb::kForRead); <BR> //获得模型空间的块农记录指针<BR> AcDbBlockTableRecord *pBlockTableRecord; <BR> pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForRead); <BR> pBlockTable->close();<BR> //生成块表的迭代器<BR> AcDbBlockTableRecordIterator *pIterator; <BR> pBlockTableRecord->newIterator(pIterator); <BR> <BR> AcGePoint3d basePoint; <BR> AcDbEntity *pEnt; <BR> <BR> char temp;<BR> int i;<BR> i=0;<BR> for (pIterator->start(); !pIterator->done(); <BR> pIterator->step())//将source.dwg中所有的Attibute进行遍历 <BR> { <BR> i++;<BR> itoa(i,temp,10);///<BR> // acutPrintf(temp);<BR> pIterator->getEntity(pEnt, AcDb::kForRead); <BR> if (pEnt->isKindOf(AcDbMText::desc()))<BR> {<BR> // acutPrintf("第% AcDbMText ",i);<BR> // acutPrintf("\n\n");<BR> AcDbMText *pAttdef; <BR> pAttdef = AcDbMText::cast(pEnt); <BR> if ( !( pAttdef->contents()==NULL) )<BR> {<BR> acutPrintf(" AcDbMText: %s \n" ,pAttdef->contents());<BR> // 获取坐标<BR> <BR> acutPrintf(" 坐标: %f %f %f\n" ,pAttdef->location());<BR> }<BR> pAttdef->close();<BR> }<BR> pEnt->close(); // use pEnt... pAttdef might be NULL <BR> }; <BR> delete pIterator; 不太会用 ok?
我考 上船还挺麻烦
页:
[1]