[求助]怎样在图形中插入一个块!
我做了一个块NS700.dwg,怎样在新的图形中插入这个块.thx!
<A href="http://bbs.mjtd.com/forum.php?mod=viewthread&tid=5823" target="_blank" >http://bbs.mjtd.com/forum.php?mod=viewthread&tid=5823</A> thx //插入块
void insertBlock(AcGePoint3d basePoint,char *blkname)<BR>{<BR> AcDbObjectId blockId;<BR> AcDbBlockTable *pBlockTable; <BR> if(!hasThisBlock(blkname)){<BR> AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse);<BR> pDb->readDwgFile(blkname);<BR> acdbHostApplicationServices()->workingDatabase()->insert(blockId,blkname,pDb);<BR> delete pDb;<BR> }<BR> else{<BR> acdbHostApplicationServices()->workingDatabase()<BR> ->getSymbolTable(pBlockTable, AcDb::kForRead);<BR> pBlockTable->getAt(blkname,blockId);<BR> }<BR> AcDbBlockReference *pBlkRef = new AcDbBlockReference;<BR> pBlkRef->setBlockTableRecord(blockId);
struct resbuf to, from;<BR> from.restype = RTSHORT;<BR> from.resval.rint = 1; // UCS<BR> to.restype = RTSHORT;<BR> to.resval.rint = 0; // WCS<BR> AcGeVector3d normal(0.0, 0.0, 1.0);<BR> acedTrans(&(normal.x), &from, &to, Adesk::kTrue, &(normal.x));<BR> pBlkRef->setPosition(basePoint);<BR> pBlkRef->setRotation(0.0);<BR> pBlkRef->setNormal(normal);
AcDbObjectId newEntId;<BR> acdbHostApplicationServices()->workingDatabase()<BR> ->getSymbolTable(pBlockTable, AcDb::kForRead);<BR> AcDbBlockTableRecord *pBlockTableRecord;<BR> pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForWrite);<BR> pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef);
pBlockTableRecord->close();<BR> pBlockTable->close();
pBlkRef->close();<BR> <BR>}
调用
char *block_name="c:\\arxprjmfc\\heada.dwg";<BR>char tbuf; <BR> AcGePoint3d pt1;
if(acedFindFile(head_name,tbuf)!=RTNORM) { //在盘上查找图块<BR> sprintf(tbuf,"file <%s> not existed.",block_name);<BR> acedAlert(tbuf);<BR> return RTERROR;<BR> }<BR> else{<BR> pt1=0.0;<BR> pt1=0.0;<BR> pt1=0.0;<BR> insertBlock(pt1,head_name);<BR> }
页:
[1]