It's OK to delete just one layout. But when remove another layout after first delete, AutoCAD crushed.
Any ideas? Thank for your patience.
CString m_strPath = _T("c:\\ttLL.dwg"); AcDbDatabase* pDbb = acdbHostApplicationServices()->workingDatabase(); AcDbDatabase* pDb = new AcDbDatabase(false, true); if (pDb->readDwgFile(m_strPath, _SH_DENYRW) != Acad::eOk) { AfxMessageBox(_T("error 1")); return; } acdbHostApplicationServices()->setWorkingDatabase(pDb); AcDbLayoutManager* pLayoutMng = acdbHostApplicationServices()->layoutManager(); Acad::ErrorStatus es=pLayoutMng->deleteLayout(_T("Layout3")); if(es!=Acad::eOk) { AfxMessageBox(_T("error 2")); } es=pLayoutMng->deleteLayout(_T("Layout2"));
if(es!=Acad::eOk)
{
AfxMessageBox(_T("error 3"));
}
acdbHostApplicationServices()->setWorkingDatabase(pDbb);
if (pDb->saveAs(m_strPath)!=Acad::eOk)
{
AfxMessageBox(_T("error 4"));
}
delete pDb;
return;
Solved! Go to Solution.
Solved by Balaji_Ram. Go to Solution.
Hi,
You should only use "setWorkingDatabase" when absolutely needed.
In this case, to delete the layouts, try this code which deletes two layouts named "MyLayout1" and "MyLayout2" :
<code>
Acad::ErrorStatus es = Acad::eOk;
AcDbDatabase *pDb = new AcDbDatabase (false, false);
pDb->readDwgFile (_T("C:\\Temp\\Test.dwg")) ;
AcApLayoutManager *pLayoutMngr =(AcApLayoutManager*)(acdbHostApplicationServices()->layoutManager());
pLayoutMngr->setCurrentLayout(ACRX_T("Model"), pDb);
pLayoutMngr->deleteLayout(ACRX_T("MyLayout1"), pDb);
pLayoutMngr->deleteLayout(ACRX_T("MyLayout2"), pDb);
pDb->saveAs(_T("C:/Temp/Test1.dwg"));
delete pDb;
</code>