Here is the situatlion:
The default file format in the AutoCAD Options Dialog is set to AutoCAD 2010 DXF.
If I open a DXf file, make a modification to it and save it using the QSave command, AutoCAD will make a backup copy of the dxf file and save the new version.
If I do the same thing but use my own ARX command to save the file using the AcDbDatabase::dxfOut function, the function returns an "eFileAccessErr" status code and AutoCAD fails to create the backup file or save the DXF file.
If I set the default format to a drawing format, load a drawing and use the AcDbDatabase::saveAs function in my command to save the file, AutoCAD will make a backup copy and save the DWG file.
Is it possible to use the AcDbDatabase::dxfOut function to make a backup copy of the loaded DXF file and save a new copy like the saveAs function does for drawing files?
If so, what do I need to do to my code to make it work.
Solved! Go to Solution.
Solved by Balaji_Ram. Go to Solution.
have you tried using acdbDxfOutAs2000, acdbDxfOutAs2004, etc etc
Can you post the code you are using to call AcDbDatabase::dxfOut() please?
Another option is to use the COM API, e.g. AcadApplication::AcadDocument.ActiveDocument.SaveAs()
Hi Richard,
I wanted to try out the COM API as my colleague Fenton Webb had already suggested and it worked.
As the "SaveAs" method in COM API cannot save dxf files, I used the "SendCommand".
I tried it this way :
1. Start AutoCAD 2014
2. Open a 2013 DXF file
3. Make some changes
4. Run the command to save the dxf file to the same path
It saved the dxf to the original file and created a .bak for it.
Here is the sample code :
#include <acadi.h> #pragma warning( disable : 4278 ) // Makes change to the tlb name based on the AutoCAD version. // For ex : acax18enu.tlb for AutoCAD 2010/2011 and 2012 // acad19enu.tlb for AutoCAD 2013 #import "acax19ENU.tlb" no_implementation raw_interfaces_only named_guids #pragma warning( default : 4278 ) static void AdskMyTestTTG(void) { Acad::ErrorStatus es; AcApDocument *pDoc = acDocManager->mdiActiveDocument(); AcDbDatabase *pDb = pDoc->database(); const TCHAR* dwgFileName; pDb->getFilename(dwgFileName); AcApDocument::SaveFormat sf = pDoc->formatForSave(); CString csDxfFullName(dwgFileName); csDxfFullName.Replace(_T(".dwg"), _T(".dxf")); csDxfFullName.Replace(_T(".DWG"), _T(".DXF")); CWinApp *pApp = acedGetAcadWinApp(); HRESULT hRes; LPDISPATCH pDisp=NULL; if (!pApp) return; pDisp=pApp->GetIDispatch(TRUE); if (!pDisp) return; CComPtr<AutoCAD::IAcadApplication> pComApp; hRes=pDisp->QueryInterface(IID_IAcadApplication, (void**)&pComApp); if (FAILED(hRes)) return; CComPtr<AutoCAD::IAcadDocument> pComDoc; hRes=pComApp->get_ActiveDocument(&pComDoc); if (FAILED(hRes)) return; VARIANT_BOOL isSaved; HRESULT hr = pComDoc->get_Saved(&isSaved); if(isSaved == 0) { CString strCommand("FILEDIA\n0\n"); BSTR bstCommand = strCommand.AllocSysString(); hRes = pComDoc->SendCommand(bstCommand); ::SysFreeString(bstCommand); // saveas // dxf // 16 // path // replace ? : yes strCommand.Format(ACRX_T("saveas\nDXF\n16\n%s\ny\n"), csDxfFullName); bstCommand = strCommand.AllocSysString(); hRes = pComDoc->SendCommand(bstCommand); ::SysFreeString(bstCommand); if (SUCCEEDED(hRes)) acutPrintf( _T("Saved.")); } else acutPrintf( _T("No changes to save.")); }
Sorry, An update to my earlier reply.
The "SaveAs" method in COM API does save dxf files, but I did not find it creating a .bak file.