哪位大侠知道怎样创建一个新的布局并在此布局中创建一个新的视口?
哪位大侠知道创建一个新的布局并在此布局中创建一个新的视口?能给出一些示例代码吗?<font color="#ee3d11">非常感谢</font> 我已解决此问题 怎么解决的啊?能否赐教一下啊? <p>jichu </p> 视楼主为粪土!//************************************************
// = 函数名称:创建新的布局
// = 函数说明:在图纸空间中以指定的名称
// strLayoutName创建新的布局
// = 返回值: 创建成功/失败 T/F
// = 参数:
//
// = 维护记录:
//
//************************************************
bool CViewPort::CreatNewLayout(CString strLayoutName)
{
AcDbLayout *pLayout = NULL;
pLayout = acdbHostApplicationServices()->
layoutManager()->findLayoutNamed(strLayoutName);
if (pLayout)
{
acutPrintf(_T("\n布局 %s 已存在"), strLayoutName);
pLayout->close();
return false;
}
Acad::ErrorStatus es;
AcDbBlockTable *pBlkTbl = NULL;
AcDbBlockTableRecord *pBlkTblRec= NULL;
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
es = pDb->getBlockTable(pBlkTbl, AcDb::kForWrite);
pBlkTblRec = new AcDbBlockTableRecord;
es = pBlkTblRec->setName(_T("*Paper_space")); // 块表记录名称
AcDbObjectId recId;
es = pBlkTbl->add(recId, pBlkTblRec);
pBlkTblRec->close();
pBlkTbl->close();
pLayout = new AcDbLayout; // 创建新的布局
es = pLayout->setLayoutName(strLayoutName); // 布局显示名称
es = pLayout->addToLayoutDict(pDb,recId);
AcDbObjectId layoutId;
pLayout->initialize(&layoutId);
pLayout->close();
acedCommand(RTSTR, _T("REGEN"), RTNONE);
return true;
}
//************************************************
// = 函数名称:创建一个图纸空间视口
// = 函数说明:在布局空间中指定一个矩形,创建矩形大小的视口
// = 返回值: 创建成功/失败 T/F
// = 参数:
//
// = 维护记录:
//
//************************************************
bool CViewPort::CreatLayoutViewPort(AcGePoint3dArray ptArr)
{
Acad::ErrorStatus es;
const ACHAR *pCh = new ACHAR;
pCh = acdbHostApplicationServices()->layoutManager()
->findActiveLayout(false);
es = acdbHostApplicationServices()->layoutManager()
->setCurrentLayout(pCh);
if (Acad::eOk != es)
{
acutPrintf(_T("fail"));
return false;
}
// 获取块表
AcDbBlockTable *pBlkTbl = NULL;
es = acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlkTbl, AcDb::kForRead);
if (Acad::eOk != es)
{
return false;
}
// 得到图纸空间中的块表记录
AcDbBlockTableRecord *pBlkTblRec = NULL;
pBlkTbl->getAt(ACDB_PAPER_SPACE, pBlkTblRec, AcDb::kForWrite);
pBlkTbl->close();
int nNum = ptArr.length();
AcGePoint3d pt1, pt2, pt3, pt4;
pt1 = ptArr.at(1);
pt2 = ptArr.at(2);
double dWidth = fabs(pt1.x - pt2.x);
double dHight = fabs(pt1.y - pt2.y);
AcGePoint3d ptCent((pt1.x+pt2.x)/2, (pt1.y+pt2.y)/2, 0);
// 新建一个视口
AcDbViewport *pViewPt = new AcDbViewport;
pViewPt->setCenterPoint(ptCent); // 设置中点
pViewPt->setHeight(dHight); // 设置大小
pViewPt->setWidth(dWidth);
pViewPt->setColorIndex(1);
AcDbObjectId viewptId;
pBlkTblRec->appendAcDbEntity(viewptId, pViewPt);
pViewPt->setOn(); // 激活
pViewPt->close();
pBlkTblRec->close();
//acdbHostApplicationServices()->layoutManager()->findLayoutNamed(_T("test"));
return true;
}
页:
[1]