/************************************************************************/
/*
插入块并分解
*/
/************************************************************************/
void CTrimeDraw::SetOutDwg(ads_point Pt)
{
CString sFileName=GetCurPath()+_T("\\分图模板1.dwg");
AcDbDatabase *pNewDb =new AcDbDatabase(Adesk::kFalse);
Acad::ErrorStatus es=pNewDb->readDwgFile(sFileName , _SH_DENYNO,false);
if (es!=Acad::eOk)
{
acutPrintf(_T("\nThe file %s cannot be opend"),sFileName);
return;
}
AcDbDatabase *pDb;
pDb =acdbHostApplicationServices ()->workingDatabase ();
CString pBlockName="TestBlock";
AcDbObjectId blockId;
if((es=pDb->insert(blockId, pBlockName,pNewDb, true))==Acad::eOk)
{
acutPrintf(_T("\ninsert ok\n"));
}
else
{
AfxMessageBox(_T("Insert failed"));
delete pNewDb;
return;
}
delete pNewDb;
acedCommand(RTSTR, _T("insert"),
RTSTR, _T("TestBlock"),
RTPOINT, Pt,
RTSTR, _T("1"),
RTSTR, _T("1"),
RTSTR, _T("0"),
RTNONE);
acdbHostApplicationServices()->setWorkingDatabase(pDb);
//分解
acedCommand(RTSTR, _T("explode"),
RTSTR, _T("L"),
0);
/*
// 获得当前数据库的块表
AcDbBlockTable *pBlkTbl;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlkTbl, AcDb::kForWrite);
// 查找用户指定的块定义是否存在
CString strBlkDef;
strBlkDef.Format(_T("%s"), _T("TestBlock"));
if (!pBlkTbl->has(strBlkDef))
{
acutPrintf(_T("\n当前图形中未包含指定名称的块定义!"));
pBlkTbl->close();
return;
}
// 获得用户指定的块表记录
AcDbObjectId blkDefId;
pBlkTbl->getAt(strBlkDef, blkDefId);
// 创建块参照对象
AcDbBlockReference *pBlkRef = new AcDbBlockReference(Pt,blkDefId);
// 将块参照添加到模型空间
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd,
AcDb::kForWrite);
AcDbObjectId entId;
pBlkTblRcd->appendAcDbEntity(entId, pBlkRef);
// 关闭数据库的对象
pBlkTblRcd->close();
pBlkRef->close();
pBlkTbl->close();
*/
}