How to select the Key signatures elements in the score through the musescore plugin.

• May 8, 2023 - 14:45

I found that using :
curScore.selection.selectRange(0,curScore.lastSegment.tick + 1,0,curScore.nstaves); //cmd(“select-all”) method

cannot select Key signatures.
key.png


Comments

In reply to by davil123

If only removing key signatures is a goal then it is possible to do. You can use the Cursor.filter property to make a cursor go through key signature segments (it only goes through chords and rests by default). The following code will allow the plugin get all key signatures, at least in the current track:

var cursor = curScore.newCursor();
cursor.filter = Segment.All;
cursor.rewind(Cursor.SCORE_START);
cursor.filter = Segment.KeySig;
cursor.next();
 
while (cursor.segment) {
    if (cursor.element) {
        var keySig = cursor.element;
        // do something with keySig    
    }
    cursor.next();
}

You can then remove the found key signatures with removeElement(keySig);

In reply to by davil123

try this:

curScore.startCmd()
var cursor = curScore.newCursor();
for (var i = 0; i < curScore.nstaves, i++) {
    cursor.rewind (Cursor.SCORE_START)
    cursor.staffIdx = i
    cursor.filter = Segment.KeySig;
    cursor.next();
    while (cursor.segment) {
        if (cursor.element) {
            var keySig = cursor.element
            keySig.visible = false
        }
        cursor.next()
    }
}
curScore.endCmd()

Do you still have an unanswered question? Please log in first to post your question.