Plugin that should return all the score elements but that doesn't
Hello
I'm trying to retrieve all the elements of a score.
I choose the approach of selecting everything from start to end with the curScore.selection.selectRange
method and analysing all the curScore.selection.elements
. With that approach I can retrieve almost everything (frame texts are missing, volta lines are also missing).
That script is pretty straightforward BUT it doesn't work at every run.
It seems that the first run selects indeed everything BUT curScore.selection.elements
returns an empty array. A second run of the plugin, returns then the expected elements.
As anyone an idea why ?
import QtQuick 2.0
import MuseScore 3.0
MuseScore {
menuPath: "Plugins.pluginName"
description: "Description goes here"
version: "1.0"
onRun: {
curScore.selection.selectRange(
curScore.firstSegment().tick,
//0,
curScore.lastSegment.tick+1, // +1 needed when we select until the end (known bug)
0,
curScore.ntracks
);
var elements=curScore.selection.elements;
console.log("Selection isRange: "+curScore.selection.isRange);
console.log("# elements: "+elements.length);
console.log("Starts at: "+((curScore.selection.startSegment)?curScore.selection.startSegment.tick:"undefined"));
console.log("Ends at: "+((curScore.selection.endSegment)?curScore.selection.endSegment.tick:"undefined"));
}
}
PS: this is run in MU3.7
Output of the first run:
Debug: Selection isRange: true
Debug: # elements: 0
Debug: Starts at: 0
Debug: Ends at: undefined
Output of the second run:
Debug: Selection isRange: true
Debug: # elements: 20973
Debug: Starts at: 0
Debug: Ends at: undefined
Comments
Did you try startCmd/endCmd around selecting the range?
I quote from duration editor:
// Select the range. !! Must be surrounded by startCmd/endCmd, otherwise a cmd(" cut ") crashes MS