4

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 Answers 2

6

Using MuseScore 3 the easiest way to generate parts PDFs is with the json batch conversion.

In the same folder where myScore.mscz is located, create a new file myScore_convert.json with the following content:

[
  {
    "in": "myScore.mscz",
    "out": [
      "myScore.pdf",
      [ "myScore-", ".pdf"]
    ]
  }
]

Open a command window, change with cd to the location of your files and issue:

musescore3 --job myScore_convert.json

This will give the following result:

convert <myScore.mscz>...
restHeight < 0.0: -10277.032723

        to <myScore.pdf>
        part <myScore-Soprano.pdf>
        part <myScore-Alto.pdf>
        part <myScore-Tenor.pdf>
        part <myScore-Bass.pdf>
... success!

And with that 5 files.

You can find more examples with other file-types at the MuseScore 3 handbook

I've tested this on Ubuntu 18.04 with MuseScore3 3.2.3.

2

EDIT: It definitely has some bugs, but it does kindof work. Feel free to use it to create something on your own.

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.

#!/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()
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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