BKChem to ODF conversion batch script

Name svg2odg.py
BKChem version 0.12.0_pre4 and higher
Category file conversion
Source svg2odg.py
Run as bkchem -b svg2odg.py [filenames]

This simple script takes all files given as arguments and converts them to the corresponding ODF Draw (.odg) files. In case a directory is given, it tries to convert all SVG files in that directory.

To run the script you just need to enter the following on the command line:

bkchem -b svg2odg.py [filenames]

To make the script simple and educational, not much checking of the input is done.

The code of the plugin is here:

import os
def convert_file( filename):
  plugin = "ODF" # the name of the export plugin
  if App.load_CDML( filename):
    outname = os.path.splitext( filename)[0] + ".odg"
    if App.plugin_export( plugin, filename=outname):
      print filename, "=>", outname
      print "export error"
for arg in Args:
  if os.path.isdir( arg):
    for f in os.listdir( arg):
      if f.endswith( ".svg"):
        convert_file( os.path.join( arg, f))
  elif os.path.isfile( arg):
    convert_file( arg)
    print "%s is neither a file nor a directory, skipping"  % arg

Personal Tools