2

I export parts a lot in Musescore. I would like to do something like this:

$ musescore -i myScore.mscz --export-parts
Exporting myScore-piano.pdf
Exporting myScore-guitar.pdf
Exporting myScore-drums.pdf

Parts were successfully exported
$

Is this possible?

I did find this:

$ musescore --export-to myScore.pdf --export-score-parts myScore.mscz

However, this generates one single pdf with the partiture and the parts. I need them in separate files.

The closest solution I have found so far is a way to generate a file containing all the parts without the partiture. It looks like this:

#!/bin/bash
IN=$1

PARTITURE=${IN%.mscz}-partiture.pdf
musescore -o $PARTITURE $IN

NO_PAGES_PARTITURE=$(pdftk $PARTITURE dump_data | grep NumberOfPages | cut -f2 -d ' ')
let NO_PAGES_PARTITURE=NO_PAGES_PARTITURE+1

FULL=${IN%.mscz}-full.pdf
musescore -o $FULL -P $IN

PARTS=${IN%.mscz}-all-parts.pdf
pdftk $FULL cat $NO_PAGES_PARTITURE-end output $PARTS

rm $FULL
2

I have now created a Python script do do this. So far I have only tried it on one file, but it seems to work.

https://github.com/klutt/klutt-musescore-tools

#!/usr/bin/python3

def main():
    import sys
    import os
    import json
    import subprocess
    import xml.etree.ElementTree as et

    if len(sys.argv) < 2:
        print("Usage: getPartNames.py <filename>")
        exit

    inFile = sys.argv[1]
    filename, fileExtention = os.path.splitext(inFile)
    mscx = filename + ".mscx"

    if fileExtention not in [".mscx", ".mscz"]:
        print("Unknown file extention: " + fileExtention)
        exit

    if fileExtention == ".mscz":
        proc = subprocess.Popen(["musescore", "-o", mscx, "-P", inFile])
        proc.wait()

    tree = et.parse(mscx)

    scoreList = []

    for score in tree.iter('Score'):
        scoreList.append(score)

    data = []
    partList = []

    for i in range(len(scoreList)-1):
        name=""
        for trackName in scoreList[i+1].iter('trackName'):
            name = trackName.text
            partList.append(trackName)
            break

        tree.getroot().remove(scoreList[i])
        tree.getroot().append(scoreList[i+1])

        partFileBase = filename + "-" + name
        partFile = partFileBase + ".mscx"
        entry = {}
        entry['in'] = partFile
        entry['out'] = partFileBase + ".pdf"
        data.append(entry)
        tree.write(partFile)

    jsonfile = filename + '.json'
    with open(jsonfile, 'w') as outfile:
        json.dump(data, outfile)

    proc = subprocess.Popen(["musescore", "-j", jsonfile])
    proc.wait()


if __name__ == "__main__":
    main()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.