Skip to content

Instantly share code, notes, and snippets.

@j0057
Last active March 31, 2016 20:27
Show Gist options
  • Save j0057/13dc8273f3ce995f2375d0395aade7d1 to your computer and use it in GitHub Desktop.
Save j0057/13dc8273f3ce995f2375d0395aade7d1 to your computer and use it in GitHub Desktop.
Convert .cap to .capx in Capella
import os, os.path
import sys
SOURCE_DIR = r'c:\users\joost\documents\capella\voorbeelden'
# a few useful functions
output = lambda s, t='': messageBox(t, str(s))
change_ext = lambda fn, ext: os.path.splitext(fn)[0] + ext
copy_mtime = lambda src, tgt: os.utime(tgt, os.stat(src)[7:9])
output('Python version: %r\nCapella version: %r' % (sys.version_info, capVersion()), 'Versions')
def converter(new_ext, write_xml):
def convert(source):
target = change_ext(source, new_ext)
if os.path.exists(target):
return
openScore(source)
if not activeScore():
return
activeScore().write(target, xml=write_xml)
closeActiveScore()
copy_mtime(source, target)
return convert
def convert_files(source_dir, source_extension, convert_function):
source_files = [ os.path.join(root, filename)
for (root, directories, filenames) in os.walk(source_dir)
for filename in filenames
if filename.endswith(source_extension) ][:4]
map(convert_function, source_files)
capx_to_cap = converter(new_ext='.cap', write_xml=0)
cap_to_capx = converter(new_ext='.capx', write_xml=1)
convert_files(SOURCE_DIR, '.cap', cap_to_capx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment