- 积分
- 403
- 明经币
- 个
- 注册时间
- 2003-4-12
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2004-5-10 08:19:00
|
显示全部楼层
//插入块
void insertBlock(AcGePoint3d basePoint,char *blkname) { AcDbObjectId blockId; AcDbBlockTable *pBlockTable; if(!hasThisBlock(blkname)){ AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse); pDb->readDwgFile(blkname); acdbHostApplicationServices()->workingDatabase()->insert(blockId,blkname,pDb); delete pDb; } else{ acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); pBlockTable->getAt(blkname,blockId); } AcDbBlockReference *pBlkRef = new AcDbBlockReference; pBlkRef->setBlockTableRecord(blockId);
struct resbuf to, from; from.restype = RTSHORT; from.resval.rint = 1; // UCS to.restype = RTSHORT; to.resval.rint = 0; // WCS AcGeVector3d normal(0.0, 0.0, 1.0); acedTrans(&(normal.x), &from, &to, Adesk::kTrue, &(normal.x)); pBlkRef->setPosition(basePoint); pBlkRef->setRotation(0.0); pBlkRef->setNormal(normal);
AcDbObjectId newEntId; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForWrite); pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef);
pBlockTableRecord->close(); pBlockTable->close();
pBlkRef->close(); }
调用
char *block_name="c:\\arxprjmfc\\heada.dwg"; char tbuf[80]; AcGePoint3d pt1;
if(acedFindFile(head_name,tbuf)!=RTNORM) { //在盘上查找图块 sprintf(tbuf,"file <%s> not existed.",block_name); acedAlert(tbuf); return RTERROR; } else{ pt1[X]=0.0; pt1[Y]=0.0; pt1[Z]=0.0; insertBlock(pt1,head_name); } |
|