Differences
This shows you the differences between two versions of the page.
bkchem_to_odf_conversion [2007/10/23 07:03] beda |
bkchem_to_odf_conversion [2024/05/02 08:09] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
===== BKChem to ODF conversion batch script ===== | ===== BKChem to ODF conversion batch script ===== | ||
- | The {{svg2odg.py|following simple script}} takes all files or directories 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. | + | ^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: | To run the script you just need to enter the following on the command line: | ||
Line 10: | Line 17: | ||
To make the script simple and educational, not much checking of the input is done. | To make the script simple and educational, not much checking of the input is done. | ||
+ | |||
+ | The code of the plugin is here: | ||
+ | |||
+ | <code python> | ||
+ | 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 | ||
+ | else: | ||
+ | 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) | ||
+ | else: | ||
+ | print "%s is neither a file nor a directory, skipping" % arg | ||
+ | </code> |