这样插入外部块?请大家帮帮忙看看那里错了
<p> AcDbObjectId blockId ;</p><p> AcDbDatabase *pDb=new AcDbDatabase(Adesk::kFalse); <br/> pDb->readDwgFile(name);<br/> blockId=pDb->xrefBlockId();</p><p>AcDbBlockReference *pBlkRef =new AcDbBlockReference ; <br/>pBlkRef->setBlockTableRecord (blockId) ; <br/>pBlkRef->setScaleFactors(AcGeScale3d(Scale,Scale,Scale)); <br/>pBlkRef->setPosition(pt) ; <br/>pBlkRef->setRotation (Rotation) ; </p><p>AcDbBlockTable *pBlockTable ; <br/>acdbHostApplicationServices()->workingDatabase()->getBlockTable (pBlockTable, AcDb::kForRead) ; <br/>AcDbBlockTableRecord *pBlockTableRecord ; <br/>pBlockTable->getAt (ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForWrite) ; <br/>pBlockTable->close () ; <br/>pBlockTableRecord->appendAcDbEntity(pBlkRef); <br/>pBlockTableRecord->close(); <br/>pBlkRef->close(); </p><p>运行的时候提示** 未定义的块 #-1</p> <p>同问</p><p>我试着用一个insert()函数来插入块。但是insert()函数老是没执行成功,没返回 Acad::eOk</p><p>也是提示找不到块定义</p><p></p> <p>你这样试试:</p><p></p><p>HDR_API BOOL fdm_InsertDwgFile(const TCHAR *FileName,const AcGePoint3d &insPt,AcDbObjectId &BlkRefId,const double ang,const TCHAR *lay)<br/>{<br/> BOOL state=FALSE;<br/> TCHAR FullPath;</p><p> if(ads_findfile(FileName,FullPath)==RTNORM)<br/> {<br/> AcDbDatabase *pDb=new AcDbDatabase(Adesk::kFalse);</p><p> if(pDb->readDwgFile(FullPath)==Acad::eOk)<br/> {<br/> if(pDb!=NULL)<br/> {<br/> AcDbObjectId ObjId;</p><p> if(acdbCurDwg()->insert(ObjId,_T("*U"),pDb)==Acad::eOk)<br/> {<br/> AcDbObjectId ReferenceId=AcDbObjectId::kNull;<br/> AcDbBlockReference *pReference=new AcDbBlockReference;<br/> pReference->setBlockTableRecord(ObjId);<br/> pReference->setPosition(insPt);<br/> pReference->setRotation(ang);<br/> pReference->setLayer(lay);<br/> if(fdm_addToModelSpace(BlkRefId,pReference)==Acad::eOk)<br/> {<br/> state=TRUE;<br/> }<br/> else delete pReference;<br/> }<br/> delete pDb;<br/> } <br/> }<br/> }<br/> <br/> return state;<br/>}</p><p>//将实体加入到(模型/图纸)空间<br/>HDR_API Acad::ErrorStatus fdm_addToModelSpace(AcDbObjectId &ObjId,AcDbEntity *pObj,BOOL IsToMs)<br/>{<br/> AcDbBlockTable *pBlockTable;<br/> AcDbBlockTableRecord *pSpaceRecord;<br/> Acad::ErrorStatus es;</p><p> es=acdbCurDwg()->getBlockTable(pBlockTable,AcDb::kForRead);<br/> if(es==Acad::eOk)<br/> {<br/> if(IsToMs) es=pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord,AcDb::kForWrite);<br/> else es=pBlockTable->getAt(ACDB_PAPER_SPACE,pSpaceRecord,AcDb::kForWrite);<br/> if(es==Acad::eOk)<br/> {<br/> es=pSpaceRecord->appendAcDbEntity(ObjId,pObj);<br/> if(es==Acad::eOk) pObj->close();<br/> pSpaceRecord->close();<br/> }<br/> pBlockTable->close();<br/> }</p><p> return es;<br/>}</p> <p>非常感谢!</p>
页:
[1]