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.

Install ODA File Converter

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.

AppImage Support

The option “unix_exec_path” defines an executable for Linux and macOS, this executable overrides the default command ODAFileConverter. Assign an absolute path to the executable to that key and if the executable is not found the add-on falls back to the ODAFileConverter command.

The option “unix_exec_path” also adds support for AppImages provided by the Open Design Alliance. Download the AppImage file and store it in a folder of your choice (e.g. ~/Apps) and make the file executable:

chmod a+x ~/Apps/ODAFileConverter_QT5_lnxX64_8.3dll_23.9.AppImage

Add the absolute path as config option “unix_exec_path” to the “odafc-addon” section:

[odafc-addon]
win_exec_path = "C:\Program Files\ODA\ODAFileConverter\ODAFileConverter.exe"
unix_exec_path = "/home/<your user name>/Apps/ODAFileConverter_QT5_lnxX64_8.3dll_23.9.AppImage"

This overrides the default command ODAFileConverter and if the executable is not found the add-on falls back to the ODAFileConverter command.

See also

For more information about config files see section: Global Options Object

Suppressed GUI

On Windows the GUI of the ODA File Converter is suppressed, on Linux you may have to install the xvfb package to prevent this, for macOS is no solution known.

Supported DXF and DWG Versions

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

Config

On Windows the path to the ODAFileConverter.exe executable 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"
unix_exec_path =

On Linux and macOS the ODAFileConverter command is located by the shutil.which() function but can be overridden since version 1.0 by the key “linux_exec_path”.

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.unix_exec_path

Absolute path to a Linux or macOS executable if set, otherwise an empty string and the default command ODAFileConverter is used.

ezdxf.addons.odafc.is_installed() bool

Returns True if the ODAFileConverter is installed.

ezdxf.addons.odafc.readfile(filename: str | PathLike, version: str | None = None, *, audit: bool = False) Drawing | None

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 | PathLike, version: str | None = 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: str | PathLike, dest: str | PathLike = '', *, version='R2018', audit=True, replace=False)

Convert source file to dest file.

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