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

AcDbDatabase::dxfout

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
bakerrl2
1585 Views, 6 Replies

AcDbDatabase::dxfout

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.

6 REPLIES 6
Message 2 of 7
fenton.webb
in reply to: bakerrl2

have you tried using acdbDxfOutAs2000, acdbDxfOutAs2004, etc etc




Fenton Webb
AutoCAD Engineering
Autodesk

Message 3 of 7
bakerrl2
in reply to: fenton.webb

Yes. I have already tried those functions with the same results. If the file is already there and opened in AutoCAD, the functions will not make a backup copy of the DXF file and replace it with the new version.

Richard L. Baker II
Svc Info Developer III
ES Apps Development US
richard.baker-ii@hp.com
T +1 512 319 3637
HP Enterprise Services
[cid:image003.png@01CE816A.419E1A40]

Please print thoughtfully
Message 4 of 7
fenton.webb
in reply to: bakerrl2

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()

 

 




Fenton Webb
AutoCAD Engineering
Autodesk

Message 5 of 7
bakerrl2
in reply to: fenton.webb

Here is the code I am trying to use. The DWG formats work just fine. AutoCAD will make a backup copy and save the new file. It doesn't work for the DXF formats.

Acad::ErrorStatus es;

CString csDwgFullName = GetDwgFilename();
grDocData.bSaveDwg = true;

AcApDocument *pDoc = acDocManager->curDocument();
AcDbDatabase *pDb = pDoc->database();

AcApDocument::SaveFormat saveFormat = pDoc->formatForSave();

bool bDwgFormat(true);
AcDb::AcDbDwgVersion dwgVersion = AcDb::kDHL_CURRENT;

switch (saveFormat)
{
case AcApDocument::k2010_dxf:
bDwgFormat = false;
dwgVersion = AcDb::kDHL_CURRENT;
break;

case AcApDocument::k2007_dxf:
bDwgFormat = false;
case AcApDocument::k2007_dwg:
dwgVersion = AcDb::kDHL_1021;
break;

case AcApDocument::k2004_dxf:
bDwgFormat = false;
case AcApDocument::k2004_dwg:
dwgVersion = AcDb::kDHL_1800;
break;

case AcApDocument::k2000_dxf:
bDwgFormat = false;
case AcApDocument::k2000_dwg:
dwgVersion = AcDb::kDHL_1015;
break;

case AcApDocument::kR14_dwg:
dwgVersion = AcDb::kDHL_1014;
break;

case AcApDocument::kR12_dxf:
bDwgFormat = false;
dwgVersion = AcDb::kDHL_1009;
break;
}

if (bDwgFormat)
{
es = pDb->saveAs(csDwgFullName, true, dwgVersion);
}
else
{
csDwgFullName.Replace(_T(".dwg"), _T(".dxf"));
csDwgFullName.Replace(_T(".DWG"), _T(".DXF"));

es = pDb->dxfOut(csDwgFullName, 16, dwgVersion);
}


Richard L. Baker II
Svc Info Developer III
ES Apps Development US
richard.baker-ii@hp.com
T +1 512 319 3637
HP Enterprise Services
[cid:image003.png@01CE8179.EF662DC0]

Please print thoughtfully
Message 6 of 7
Balaji_Ram
in reply to: bakerrl2

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."));
}

 

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Message 7 of 7
Balaji_Ram
in reply to: Balaji_Ram

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.

 

 

 

 



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