|
Programmatically saving the active document in C++/ARX applications 以编程方式将活动文档保存在 C++/ARX 应用程序中
[code]void saveDwg()
{
try
{
IAcadApplicationPtr pApp =
acedGetAcadWinApp()->GetIDispatch(FALSE);
IAcadDocumentPtr pDoc;
pApp->get_ActiveDocument(&pDoc);
pDoc->Save();
}
catch(_com_error& e)
{
acutPrintf(_T("\nCOM error: %s"), (ACHAR*)e.Description());
}
}
Second Approach:
#include <acadi_i.c>
// minimal error check for code brevity
void saveDwg()
{
CWinApp* pWinApp = acedGetAcadWinApp();
if(!pWinApp)
return;
CComPtr<IDispatch> pDisp = pWinApp->GetIDispatch(TRUE);
if(!pDisp)
return;
CComPtr<IAcadApplication> pComApp;
HRESULT hr = pDisp->QueryInterface(IID_IAcadApplication,
(void**)&pComApp);
if(FAILED(hr))
return;
CComPtr<IAcadDocument> pDoc;
hr = pComApp->get_ActiveDocument(&pDoc);
if(FAILED(hr))
return;
hr = pDoc->Save();
if(FAILED(hr))
acutPrintf(_T("\nFailed to save current dwg file."));
}[/code] |
|