|
[code]//读*.dwg文件以textDrawing块名插入打开文件
void inserblk()
{
// 建立一个空的数据库对象(Adesk::kTrue则不为空)
AcDbDatabase *pDwg =new AcDbDatabase (Adesk::kFalse) ;
// 设置插入块的路径
pDwg->readDwgFile("d:\\1.dwg");
AcDbObjectId blockId;
Acad::ErrorStatus es = acdbHostApplicationServices()->workingDatabase()->insert(blockId, "mydrawing", pDwg, Adesk::kFalse);
if ( es != Acad::eOk )
{
acutPrintf ("\n插入块错误.");
}
// 释放内存
delete pDwg;
// 上面创建了“名字是myfile的块定义AcDbBlockTableRecord”,
// ObjectId是blockId,接着就可以实例AcDbBlockReference对象,
// 创建INSERT实体了。
AcDbBlockReference *pBlkRef =new AcDbBlockReference();
pBlkRef->setBlockTableRecord (blockId) ;
// 输入插入点
ads_point pickPt;
int retCode;
// 限制用户必须选择或输入点(输入模式:x,y,z)
acedInitGet(RSG_NONULL, NULL);
acedGetPoint(NULL, "\n请选择插入点:", pickPt);
//---- 设置插入点,旋转角度,比例等等
pBlkRef->setPosition(AcGePoint3d(pickPt[X],pickPt[Y],0.0)) ;
pBlkRef->setRotation(0.0);
// 获得模型空间块表记录
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
pBlockTable->close();
//----- 添加块引用pBlkRef实体到模型空间
AcDbObjectId newEntId ;
pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef);
// 释放资源
pBlockTableRecord->close();
pBlkRef->close();
}[/code] |
|