How to add horizontal frame by plugin?

• Nov 20, 2021 - 09:33

Please, how is it possible, to add horizontal frame by plugin.
In source, it seems to be done https://github.com/musescore/MuseScore/blob/1bf03517546291f07f9c70ed2db…

but when I tried

onRun: {
      var cursor = curScore.newCursor();
      cursor.rewind(Cursor.SCORE_START);
      cursor.track = 0; 
      var sym = newElement(Element.HBOX);
      cursor.add(sym);
 
      Qt.quit()
      }
}

it does nothing.
Thank You for help.


Comments

It does something for me, but perhaps not immediately obvious because it doesn't do what you'd expect (nor can I explain why).

But the frame is added to the end of the score seemingly regardless of the cursor position. And you need a layout trigger to see it (for example change between page view and single page view).

In reply to by scorster

This topic is not related to your discussion, but is about a Plugin API command not performing the requested action; and behaving differently than what a quick glance at the code behind it indicates.

The plugin API code quite clearly shows that the current segment's measure is requested and the element is added to that; so the expected outcome of the plugin command should be identical to what happens if you as a user target that measure and add the element to it (ie have the frame be inserted before the current measure).
Instead the plugin API action to insert seems to perform an append instead for no obvious code reason.

This has nothing to do with the request for an additional command to insert after the target point of reference; which then in turn might or might not also be made possible via the Plugin API.

In reply to by scorster

I suspect it's meant to mirror the behavior of the append measures command, where appending to the end of the score is by far the most common - it's what you do every time you run out of measures or realize you are getting close to running out. But indeed, an append after selection would make sense too.

In reply to by Marc Sabatella

Marc, I don't think so. It tries to add box to selected measure, exactly, as it does with "staff type change" for example.

onRun: {
      var cursor = curScore.newCursor();
      cursor.rewind(Cursor.SCORE_START);
      cursor.track = 0; 
 
      var box = newElement(Element.HBOX);
      var schange = newElement(Element.STAFFTYPE_CHANGE);
      cursor.nextMeasure()
      cursor.add(box);
      cursor.add(schange);
      console.log(box.parent, schange.parent, box.parent.is(schange.parent))
      Qt.quit()
      }

I think, problem is, that HBoxs parent shouldn't be a "measure", but a "system", and hbox should be added in front of selected measure.

In reply to by sammik

I was responding more to the (now deleted) comment that the append functionality doesn’t menu make sense for the menu command. I think it does, least for consistency with what appending measures means. But how to get the command working in a plugin isn’t something I have insight into. I would think executing the command via plugin would do exactly the same as executing via menu or shortcut. But it looks like you aren’t using the command here, and instead are trying to do it in a more low level way. I guess I’d recommend the command then ;-)

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