logo4 Evolution is progress—                          
progress is creativity.        

Python Programm to Convert old Corel Draw Files

view blog view wiki view wiki view wiki


I have a huge library of CorelDraw files both *.cmx and *.cdr. As I use Ubuntu now, I have no option to preview these files in my explorer. Therefore these files need to be translated into *.svg files. The uniconvert routine produces an error as already reported here. Moreover, it allows only one file being converted at a time and it is boring to type all the filenames of a huge library. Therefore I need a python program that does the job.


Step 1

Creating a scrip that reads all files from a directory tree recursively.

import os, fnmatch

def all_files(root, patterns='*', single_level=False, yield_folders=False):
    # expand patterns from semicolon-separated string to list
    patterns = patterns.split(';')
    for path, subdirs, files in os.walk(root):
        if yield_folders:
        for name in files:
            for pattern in patterns:
                if fnmatch.fnmatch(name, pattern):
                    yield path, name
            if single_level:

for path, name in all_files('my-graphic-root-directory','*.[cC][mM][xX];*.[cC][dD][rR]'):

# create some newname and oldname from path and name
# change the extension to .svg ATTENTION capital letters (.SVG) won't work 

Step 2

The conversion routine has to be created. The uniconverter module has to be included in PYTHONPATH, which is easily accomplished with Eclipse/Pydev environment.

import uniconvertor

def myuniconv(oldname,newname):
    _pkgdir = 'directory-where-the-converter-resides'    
    sys.path.insert(1, _pkgdir)
    from uniconvertor.app.io import load
    from uniconvertor.app.plugins import plugins
    import uniconvertor.app
    doc = load.load_drawing(input_file)
    extension = os.path.splitext(output_file)[1]
    fileformat = plugins.guess_export_plugin(extension)
    if fileformat:
        saver = plugins.find_export_plugin(fileformat)
        saver(doc, output_file)
        sys.stderr.write('ERROR: unrecognized extension %s\n' % extension)

Step 3

Still the error is produced wich is probably due to improper installation or configuration. I installed uniconverter through Synaptic Package Manager, and all my uniconverter modules reside in different subdirectories of /usr. Nothing is installed into my home directory. So I copied all uniconverter files into my project changed PYTHONPATH accordingly and edited the file configurator.py in module app.conf as indicated below.

#       self.user_home_dir = gethome()
	self.user_home_dir = '/home/mato/workspace/py/ConvertCMX'
#	self.user_config_dir = os.path.join(self.user_home_dir,'.uniconvertor')
	self.user_config_dir = os.path.join(self.user_home_dir,'uniconvertor')

After that the programm worked in my eclipse environment. The following warnings can be easily ignored.

No plugin-type information in /home/mato/workspace/py/ConvertCMX/uniconvertor/app/plugins/Filters/__init__.py
No plugin-type information in /home/mato/workspace/py/ConvertCMX/uniconvertor/app/plugins/Filters/__init__.py


The produced svg files contain the drawing in the lower left angle of a rectangle. If the drawing exceeds the size of the rectangle the is seems to be clipped off. Probably, I have to invest further research into that.

Tags: Software


(c) Mato Nagel, Weißwasser 2004-2013, Disclaimer