ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Failed to delete more than one layout

1 REPLY 1
SOLVED
Reply
Message 1 of 2
chunyuran
391 Views, 1 Reply

Failed to delete more than one layout

It's OK to delete just one layout. But when remove another layout after first delete, AutoCAD crushed.

Any ideas? Thank for your patience.

QQ20130903114339.png

 

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;

 

1 REPLY 1
Message 2 of 2
Balaji_Ram
in reply to: chunyuran

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>



Balaji
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost