[ARX]大家帮忙看一下这段程序
<BR>void InsertBlock(ads_point basePoint,double angle)<BR>{<BR> AcDbDatabase *pDwg =new AcDbDatabase (Adesk::kFalse) ; <BR> Acad::ErrorStatus es;<BR> es=pDwg->readDwgFile ("C:\\ccd.dwg") ; <BR> <BR> if(es==Acad::eOk)<BR> {<BR> AfxMessageBox("readDwgFile Successful!");<BR> return;<BR> }<BR> AcDbObjectId blockId ; <BR> <BR> es = acdbHostApplicationServices()->workingDatabase()->insert (blockId, "myfile", pDwg, <BR> Adesk::kFalse) ; <BR> if ( es != Acad::eOk ) <BR> acutPrintf ("\n插入块错误.") ; <BR> delete pDwg ; <BR> <BR> <BR> AcDbBlockReference *pBlkRef =new AcDbBlockReference ; <BR> pBlkRef->setBlockTableRecord (blockId) ;AcGePoint3d inbase(basePoint, basePoint, 0.0); <BR> pBlkRef->setPosition (inbase) ; <BR> pBlkRef->setRotation (0.0) ;<BR> pBlkRef->setScaleFactors(AcGeScale3d(1,1,1));<BR> <BR> AcDbBlockTable *pBlockTable ; <BR> <BR> es=acdbHostApplicationServices()->workingDatabase()->getBlockTable (pBlockTable, AcDb::kForRead) ; <BR> if(es!=Acad::eOk)<BR> acutPrintf("getBlockTable faile!");<BR> <BR> AcDbBlockTableRecord *pBlockTableRecord ; <BR> es=pBlockTable->getAt (ACDB_MODEL_SPACE, pBlockTableRecord, <BR> AcDb::kForWrite) ; <BR> <BR> if(es!=Acad::eOk)<BR> acutPrintf("getAt faile!");<BR> <BR> pBlockTable->close () ;<BR> AcDbObjectId newEntld;<BR> pBlockTableRecord->appendAcDbEntity(newEntld,pBlkRef);<BR> pBlockTableRecord->close();<BR> pBlkRef->close();<BR> <BR>}
为什么我调用了该函数,插入的图块显示不出来的,是什么原因!
谢谢
我也是个菜鸟不知道我说的对不对,你的代码第一个if语句:
if(es==Acad::eOk)<BR> {<BR> AfxMessageBox("readDwgFile Successful!");<BR> return;<BR> }<BR>如果成功读入了ccd.dwg文件则readDwgFile的返回值是Acad::eOk,由于return 语句的作用是不是就退出了该函数,而后面的语句根本就没有执行,你把这个if语句删掉试试 不关上面的事,我把上面的屏蔽掉也是这个样了,还请大家帮一下忙! Acad::ErrorStatus es = Acad::eOk;<BR> //获得数据库指定块的ID<BR> AcDbBlockTable *pBTR;<BR> es = pBackDb->getBlockTable(pBTR,AcDb::kForRead);<BR> AcDbObjectId blkId;<BR> es = pBTR->getAt(BlockId,blkId);<BR> pBTR->close();<BR> //将指定的块插入到一个新的数据库<BR> AcDbDatabase *pNewDb = NULL;<BR> es = pBackDb->wblock(pNewDb,blkId);<BR> delete pBackDb;<BR> //将新的数据库插入到当前数据库中形成一个新的块<BR> AcDbObjectId newBlkId;<BR> es = acdbCurDwg()->insert(newBlkId,BlockId,pNewDb,false);<BR> delete pNewDb; 把你
es = acdbHostApplicationServices()->workingDatabase()->insert (blockId, "myfile", pDwg, <BR> Adesk::kFalse) ; <BR> if ( es != Acad::eOk ) <BR> acutPrintf ("\n插入块错误.") ; <BR> delete pDwg ;
换成上面的,你自己再检查一下 你只是插入了块,还需要进行块引用
AcDbObjectId idBlock; <BR> AcDbBlockReference* pBlock=new AcDbBlockReference;<BR> pBlock->setPosition(ptCenter);<BR> pBlock->setLayer(m_idLineLayer);<BR> pBlock->setBlockTableRecord(idBlock);<BR> pBlock->setScaleFactors(AcGeScale3d(m_dPlotScale)); <BR> idArray.append(CLjDwg::AddEntity(pBlock));<BR> pBlock->close();
页:
[1]