|
[code]void createLyt()
{
Acad::ErrorStatus es;
AcDbObjectId LObjId, BTRId;
AcDbDatabase *curDocDB =acdbHostApplicationServices()->workingDatabase();
AcApLayoutManager *layoutMngr =
(AcApLayoutManager*)(acdbHostApplicationServices()->layoutManager());
curDocDB->setTilemode(Adesk::kFalse);
const ACHAR *actLayoutName = layoutMngr->findActiveTab();
AcDbLayout* pSrc = layoutMngr->findLayoutNamed(actLayoutName, TRUE);
if (pSrc == NULL)
return;
//pSrc must be demoted to kForRead
pSrc->downgradeOpen();
//create new layout with next available name
ACHAR *newLName = layoutMngr->getNextNewLayoutName();
if (Acad::eOk != layoutMngr->createLayout(newLName, LObjId, BTRId))
{ acutDelString(newLName);
return;
//failure
}
AcDbLayout* pTarget = layoutMngr->findLayoutNamed(newLName, TRUE);
acutDelString(newLName);
if (pTarget != NULL)
{
es = pTarget->copyFrom(pSrc);
pSrc->close();
if (es != Acad::eOk)
{
//unsuccessful property copy - erase new layout
pTarget->erase();
pTarget->close();
}
else
{
pTarget->close();
layoutMngr->updateLayoutTabs();
}
}
}
To clone a complete layout with properties and entities…
void createClone()
{
Acad::ErrorStatus es;
AcDbDatabase *curDocDB =acdbHostApplicationServices()->workingDatabase();
AcApLayoutManager *layoutMngr =
(AcApLayoutManager*)(acdbHostApplicationServices()->layoutManager());
curDocDB->setTilemode(Adesk::kFalse);
const ACHAR *actLayoutName = layoutMngr->findActiveTab();
//no layout objects may be open kForWrite during getNextNewLayoutName()
ACHAR *cloneName = layoutMngr->getNextNewLayoutName();
AcDbLayout *pSrc = layoutMngr->findLayoutNamed(actLayoutName, TRUE);
if (pSrc == NULL)
{
acutDelString(cloneName);
return;
}
es = layoutMngr->cloneLayout(pSrc, cloneName);
acutDelString(cloneName);
pSrc->close();
if (es == Acad::eOk)
layoutMngr->updateLayoutTabs();
}[/code] |
|