- 积分
- 367
- 明经币
- 个
- 注册时间
- 2010-8-22
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
创建一个新布局:
- AcDbBlockTableRecord* CViewPort::CreatNewLayout(CString strLayoutName)
- {
- AcDbLayout *pLayout = NULL;
- AcDbBlockTableRecord *pBlkTblRec= NULL;
- pLayout = acdbHostApplicationServices()->
- layoutManager()->findLayoutNamed(strLayoutName);
- if (pLayout)
- {
- acutPrintf(_T("\n布局 %s 已存在"), strLayoutName);
- pLayout->close();
- return pBlkTblRec;
- }
- Acad::ErrorStatus es;
- AcDbBlockTable *pBlkTbl = NULL;
-
- AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
- es = pDb->getBlockTable(pBlkTbl, AcDb::kForWrite);
- if (Acad::eOk != es)
- {
- return pBlkTblRec;
- }
- pBlkTblRec = new AcDbBlockTableRecord;
- es = pBlkTblRec->setName(_T("*Paper_Space")); // 块表记录名称
- if (Acad::eOk != es)
- {
- return pBlkTblRec;
- }
-
- es = pBlkTbl->add(recId, pBlkTblRec);
- pBlkTblRec->close();
- pBlkTbl->close();
- pLayout = new AcDbLayout; // 创建新的布局
- es = pLayout->setLayoutName(strLayoutName); // 布局显示名称
- es = pLayout->addToLayoutDict(pDb,recId);
- pLayout->close();
- acedCommand(RTSTR, _T("REGEN"), RTNONE);
- return pBlkTblRec;
- }
复制代码
创建好后, 我再将一个外部的DWG文件作为一个块插入到新建的布局中
- bool CEntSet::InsBlk(CString strBlkName,AcGePoint3dArray ptArr)
- {
- Acad::ErrorStatus es;
- AcDbBlockTable *pBlkTbl = NULL;
- es = acdbHostApplicationServices()->workingDatabase()
- ->getBlockTable(pBlkTbl, AcDb::kForRead);
- if (Acad::eOk != es)
- {
- acutPrintf(_T("\n获取块表失败"));
- return false;
- }
- if(!pBlkTbl->has(strBlkName))
- {
- acutPrintf(_T("\n当前图形中未包含此块:%s"), strBlkName);
- pBlkTbl->close();
- return false;
- }
- AcDbObjectId blkTRecId;
- es = pBlkTbl->getAt(strBlkName, blkTRecId); // 获取块表ID
- if(Acad::eOk != es)
- {
- return false;
- }
- // 新建块表引用
- AcGePoint3d ptOri(0,0,0);
- AcDbBlockReference *pBlkRef = new AcDbBlockReference(ptOri,blkTRecId);
-
- // 得到图纸空间块表记录
- AcDbBlockTableRecord *pBlkTblRec = NULL;
- es = pBlkTbl->getAt(_T("*Paper_Space"), pBlkTblRec, AcDb::kForWrite);
- pBlkTbl->close();
- AcDbObjectId objId;
- es = pBlkTblRec->appendAcDbEntity(objId, pBlkRef); // 加入图纸空间
- CString strFrmName;
- int nPos = g_strFramePath.ReverseFind(_T('\\'));
- strFrmName = g_strFramePath.Mid(nPos+1);
- strFrmName = strFrmName.TrimRight(_T(".dwg"));
- pBlkRef->close();
- pBlkTblRec->close();
- acedCommand(RTSTR, _T("REGEN"), RTNONE);
- return true;
- }
复制代码
现在的问题是, 每次都都插在"布局1"上, 怎么使这个块插入到新建的布局空间上呢? 谢谢啊
|
|