Lua Scripts: moving to Engrave - Graphic mode

I have a number of Lua scripts that move to Engrave move, do a thing, then move back to Write mode. Usually the action is applied to the current selection, e.g. hiding stems on selected notes; applying a Break, etc.

Trouble is, if I was previously using one of the ‘other’ sub-modes of Engrave mode - Staff Spacing, Note Spacing, Frames, - then the selection is lost. so I can’t just script an action to change to Graphic Editing mode.

So, do any of the Lua scripting fiends know a command to move from Write mode to Graphic Editing all in one go, while maintaining the current selection?

I might misunderstand something here, but wouldn’t you have the exact same problem if you performed such a switch manually (meaning the loss of selection when entering Engrave Mode while one of the sub modes is still active from previous use)? Since you can basically only patch together regular UI actions, I can’t see how scripting could get around this.

And also, just to add some mixed messaging… there are some edits (not too many, in my estimation) that can be done via scripting without a mode change, while doing the same thing manually is not possible without changing modes. Probably the one that is known to a few people here is adding Layout Breaks. Depending on the task, just trying commands out without any change of mode at all might solve your problem (don’t get your hopes up particularly high, though).

Thanks, Alexander: I was hoping there might be an ‘all in one’ command that switched to the correct subtool in one go, without actually entering the others and losing the selection. It may be wishful thinking.

Yes, I know some actions don’t need Engrave mode. But some do. ! Not to worry.