ODA File Converter Support

Use an installed ODA File Converter for converting between different versions of .dwg, .dxb and .dxf.

Warning

Execution of an external application is a big security issue! Especially when the path to the executable can be altered.

To avoid this problem delete the ezdxf.addons.odafc.py module.

The ODA File Converter has to be installed by the user, the application is available for Windows XP, Windows 7 or later, Mac OS X, and Linux in 32/64-bit RPM and DEB format.

At least at Windows the GUI of the ODA File Converter pops up on every call.

ODA File Converter version strings, you can use any of this strings to specify a version, 'R..' and 'AC....' strings will be automatically mapped to 'ACAD....' strings:

ODAFC

ezdxf

Version

ACAD9

not supported

AC1004

ACAD10

not supported

AC1006

ACAD12

R12

AC1009

ACAD13

R13

AC1012

ACAD14

R14

AC1014

ACAD2000

R2000

AC1015

ACAD2004

R2004

AC1018

ACAD2007

R2007

AC1021

ACAD2010

R2010

AC1024

ACAD2013

R2013

AC1027

ACAD2018

R2018

AC1032

On Windows systems the path of the ODAFileConverter.exe application is stored in the config file (see ezdxf.options) in the “odafc-addon” section as key “win_exec_path”, the default entry is:

[odafc-addon]
win_exec_path = "C:\Program Files\ODA\ODAFileConverter\ODAFileConverter.exe"

On Linux and macOS the ODAFileConverter command is located by the shutil.which() function.

Usage:

from ezdxf.addons import odafc

# Load a DWG file
doc = odafc.readfile('my.dwg')

# Use loaded document like any other ezdxf document
print(f'Document loaded as DXF version: {doc.dxfversion}.')
msp = doc.modelspace()
...

# Export document as DWG file for AutoCAD R2018
odafc.export_dwg(doc, 'my_R2018.dwg', version='R2018')
ezdxf.addons.odafc.win_exec_path

Path to installed ODA File Converter executable on Windows systems, default is "C:\Program Files\ODA\ODAFileConverter\ODAFileConverter.exe".

ezdxf.addons.odafc.is_installed() bool

Returns True if the ODAFileConverter is installed.

New in version 0.18.

ezdxf.addons.odafc.readfile(filename: str, version: Optional[str] = None, *, audit: bool = False) Optional[Drawing]

Uses an installed ODA File Converter to convert a DWG/DXB/DXF file into a temporary DXF file and load this file by ezdxf.

Parameters
  • filename – file to load by ODA File Converter

  • version – load file as specific DXF version, by default the same version as the source file or if not detectable the latest by ezdxf supported version.

  • audit – audit source file before loading

Raises
  • FileNotFoundError – source file not found

  • odafc.UnknownODAFCError – conversion failed for unknown reasons

  • odafc.UnsupportedVersion – invalid DWG version specified

  • odafc.UnsupportedFileFormat – unsupported file extension

  • odafc.ODAFCNotInstalledError – ODA File Converter not installed

ezdxf.addons.odafc.export_dwg(doc: Drawing, filename: str, version: Optional[str] = None, *, audit: bool = False, replace: bool = False) None

Uses an installed ODA File Converter to export the DXF document doc as a DWG file.

A temporary DXF file will be created and converted to DWG by the ODA File Converter. If version is not specified the DXF version of the source document is used.

Parameters
  • docezdxf DXF document as Drawing object

  • filename – output DWG filename, the extension will be set to “.dwg”

  • version – DWG version to export, by default the same version as the source document.

  • audit – audit source file by ODA File Converter at exporting

  • replace – replace existing DWG file if True

Raises
  • FileExistsError – target file already exists, and argument replace is False

  • FileNotFoundError – parent directory of target file does not exist

  • odafc.UnknownODAFCError – exporting DWG failed for unknown reasons

  • odafc.ODAFCNotInstalledError – ODA File Converter not installed

ezdxf.addons.odafc.convert(source: Union[str, Path], dest: Union[str, Path] = '', *, version='R2018', audit=True, replace=False)

Convert source file to dest file.

New in version 0.18.

The file extension defines the target format e.g. convert("test.dxf", "Test.dwg") converts the source file to a DWG file. If dest is an empty string the conversion depends on the source file format and is DXF to DWG or DWG to DXF. To convert DXF to DXF an explicit destination filename is required: convert("r12.dxf", "r2013.dxf", version="R2013")

Parameters
  • source – source file

  • dest – destination file, an empty string uses the source filename with the extension of the target format e.g. “test.dxf” -> “test.dwg”

  • version – output DXF/DWG version e.g. “ACAD2018”, “R2018”, “AC1032”

  • audit – audit files

  • replace – replace existing destination file

Raises
  • FileNotFoundError – source file or destination folder does not exist

  • FileExistsError – destination file already exists and argument replace is False

  • odafc.UnsupportedVersion – invalid DXF version specified

  • odafc.UnsupportedFileFormat – unsupported file extension

  • odafc.UnknownODAFCError – conversion failed for unknown reasons

  • odafc.ODAFCNotInstalledError – ODA File Converter not installed