|
Acad::ErrorStatus open_save_close(const ACHAR *DWGFileName)
{
struct resbuf DWGMode;
int nRetVal = acedGetVar(_T("SDI"), &DWGMode);
if ( RTNORM != nRetVal) return Acad::eKeyNotFound;
if (DWGMode.resval.rint != 0)
return Acad::eCantOpenFile;
Acad::ErrorStatus es = Acad::eOk;
CComPtr<AutoCAD::IAcadDocument> IDoc;
CComPtr<AutoCAD::IAcadApplication> IApp;
CComPtr<AutoCAD::IAcadDocuments> IDocs;
CComPtr<IDispatch> pDisp = acedGetAcadWinApp()->GetIDispatch(TRUE);
if(!pDisp) return Acad::eCantOpenFile;
HRESULT hr = pDisp->QueryInterface(AutoCAD::IID_IAcadApplication,(void**)&IApp);
if (FAILED(hr)) return Acad::eCantOpenFile;
hr = IApp->get_Documents(&IDocs);
if(FAILED(hr)) return Acad::eCantOpenFile;
_variant_t b(VARIANT_FALSE);
hr = IDocs->Open(_bstr_t(DWGFileName),b,b,&IDoc);
if(FAILED(hr)) return Acad::eCantOpenFile;
hr = IApp->ZoomExtents();
if(FAILED(hr)) return Acad::eCantOpenFile;
VARIANT saveChanges, fileName;
saveChanges.vt = VT_BOOL;
saveChanges.boolVal = VARIANT_FALSE;
fileName.vt = VT_ERROR;
fileName.scode = DISP_E_PARAMNOTFOUND;
IDoc->Save();
IDoc->Close(saveChanges, fileName);
return Acad::eOk;
} |
|