yunzhong80 发表于 2008-6-9 09:02:00

这样插入外部块?请大家帮帮忙看看那里错了

<p>&nbsp;AcDbObjectId blockId ;</p><p>&nbsp;AcDbDatabase *pDb=new AcDbDatabase(Adesk::kFalse); <br/>&nbsp;pDb-&gt;readDwgFile(name);<br/>&nbsp;blockId=pDb-&gt;xrefBlockId();</p><p>AcDbBlockReference *pBlkRef =new AcDbBlockReference ; <br/>pBlkRef-&gt;setBlockTableRecord (blockId) ; <br/>pBlkRef-&gt;setScaleFactors(AcGeScale3d(Scale,Scale,Scale)); <br/>pBlkRef-&gt;setPosition(pt) ; <br/>pBlkRef-&gt;setRotation (Rotation) ; </p><p>AcDbBlockTable *pBlockTable ; <br/>acdbHostApplicationServices()-&gt;workingDatabase()-&gt;getBlockTable (pBlockTable, AcDb::kForRead) ; <br/>AcDbBlockTableRecord *pBlockTableRecord ; <br/>pBlockTable-&gt;getAt (ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForWrite) ; <br/>pBlockTable-&gt;close () ; <br/>pBlockTableRecord-&gt;appendAcDbEntity(pBlkRef); <br/>pBlockTableRecord-&gt;close(); <br/>pBlkRef-&gt;close(); </p><p>运行的时候提示** 未定义的块 #-1</p>

luoxiru 发表于 2008-6-15 20:51:00

profawkes 发表于 2008-6-17 08:55:00

<p>同问</p><p>我试着用一个insert()函数来插入块。但是insert()函数老是没执行成功,没返回 Acad::eOk</p><p>也是提示找不到块定义</p><p></p>

hdr0427168 发表于 2008-6-17 10:55:00

<p>你这样试试:</p><p></p><p>HDR_API BOOL fdm_InsertDwgFile(const TCHAR *FileName,const AcGePoint3d &amp;insPt,AcDbObjectId &amp;BlkRefId,const double ang,const TCHAR *lay)<br/>{<br/>&nbsp; BOOL state=FALSE;<br/>&nbsp; TCHAR FullPath;</p><p>&nbsp; if(ads_findfile(FileName,FullPath)==RTNORM)<br/>&nbsp; {<br/>&nbsp;&nbsp;&nbsp; AcDbDatabase *pDb=new AcDbDatabase(Adesk::kFalse);</p><p>&nbsp;&nbsp;&nbsp; if(pDb-&gt;readDwgFile(FullPath)==Acad::eOk)<br/>&nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(pDb!=NULL)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbObjectId ObjId;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(acdbCurDwg()-&gt;insert(ObjId,_T("*U"),pDb)==Acad::eOk)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbObjectId ReferenceId=AcDbObjectId::kNull;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbBlockReference *pReference=new AcDbBlockReference;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pReference-&gt;setBlockTableRecord(ObjId);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pReference-&gt;setPosition(insPt);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pReference-&gt;setRotation(ang);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pReference-&gt;setLayer(lay);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(fdm_addToModelSpace(BlkRefId,pReference)==Acad::eOk)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; state=TRUE;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else delete pReference;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delete pDb;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; }<br/>&nbsp; }<br/>&nbsp; <br/>&nbsp; return state;<br/>}</p><p>//将实体加入到(模型/图纸)空间<br/>HDR_API Acad::ErrorStatus fdm_addToModelSpace(AcDbObjectId &amp;ObjId,AcDbEntity *pObj,BOOL IsToMs)<br/>{<br/>&nbsp; AcDbBlockTable *pBlockTable;<br/>&nbsp;AcDbBlockTableRecord *pSpaceRecord;<br/>&nbsp; Acad::ErrorStatus es;</p><p>&nbsp; es=acdbCurDwg()-&gt;getBlockTable(pBlockTable,AcDb::kForRead);<br/>&nbsp;if(es==Acad::eOk)<br/>&nbsp; {<br/>&nbsp;&nbsp;&nbsp; if(IsToMs) es=pBlockTable-&gt;getAt(ACDB_MODEL_SPACE, pSpaceRecord,AcDb::kForWrite);<br/>&nbsp;&nbsp;&nbsp; else es=pBlockTable-&gt;getAt(ACDB_PAPER_SPACE,pSpaceRecord,AcDb::kForWrite);<br/>&nbsp;&nbsp; if(es==Acad::eOk)<br/>&nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; es=pSpaceRecord-&gt;appendAcDbEntity(ObjId,pObj);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(es==Acad::eOk) pObj-&gt;close();<br/>&nbsp;&nbsp;&nbsp; &nbsp;pSpaceRecord-&gt;close();<br/>&nbsp;&nbsp;&nbsp; }<br/>&nbsp;&nbsp;&nbsp; pBlockTable-&gt;close();<br/>&nbsp; }</p><p>&nbsp;return es;<br/>}</p>

yunzhong80 发表于 2008-6-17 19:40:00

<p>非常感谢!</p>
页: [1]
查看完整版本: 这样插入外部块?请大家帮帮忙看看那里错了