Plugin can set selection but does not see what’s in it
If I run SelectTest.qml I get the desired selection , but I invariably (I tried cursor.rewinds etc) get :
SelectTest.qml
Debug: Hello World
Debug: el.length = 0
What am I doing wrong?
EDIT: If I select the measure manually & comment out the programmatic selection
//curScore.selection.selectRange(startTick, endTick+1, 0, curScore.nstaves)
it works: Debug: el.length = 21 (or whatever > 0)
Comments
You forgot to persist your score-changing action (the selection) by wrapping it between startCmd and endCmd.
Sidenote: don't use Qt.quit; check out the plugin development handbook page on why not.
In reply to You forgot to persist your… by jeetee
Many thanks & also for the Qt.quit discussion (https://musescore.org/en/node/304874#comment-1001236)
In reply to Many thanks & also for the… by elsewhere
Fun fact to know: To see the notes in the selection use Element.NOTE. Element.CHORD does not work here...
for (var j = 0; j < el.length; j++){
var e = el[j];
if(e.type == Element.NOTE) {
console.log ("note.pitch ", e.pitch)
}
}