Remove all dynamics script

I was looking for an easy way to remove all dynamics, and this may be overkill, so I made a Lua script to do this by recording a macro and wanted to share it. If for no other reason to demonstrate the power of scripting in Dorico 6, and the need for possible development to identify a particular intensity of dynamic (or many other things possibly). For example, instead of only:

app:doCommand([[Edit.SelectAll]])

How useful would it be if there were a series of scripting commands such as:

app:doCommand([[Edit.Selectp]]) or app:doCommand([[Edit.Selectppp]])

Then you would have a number of useful scripts to do specific repetitive tasks.

If you were to do this the traditional way: Select all (CTRL-A) → Filter (Right-click) → All Dynamics → Delete… not too hard, and it is how I have been doing it since I started using Dorico.

If you use a script you select 'Script → Run Script… → select your script and hit Enter.

When you save this macro, the script contains the following code:

local app=DoApp.DoApp()
app:doCommand([[File.AutoSave]])
app:doCommand([[Edit.SelectAll]])
app:doCommand([[Filter.Dynamics]])
app:doCommand([[Edit.Delete]])

Maybe it’s like using a sledgehammer to swat a fly, but I thought it was interesting and wanted to share my opinion.

Cheers

Select all, right-click>filter>all dynamics. Delete

I would have said that was a succint answer to what your query was, showing that it’s unnecessary to write a script for something that’s already baked in to the program… I’m all for the power of scripting to achieve something that Dorico (or any other program) can’t do out of the box but writing a script for something that the software does in 3 strokes is a little, as you said, hammer to crack a walnut?

That’s the way the initial answer came across to me…

My 2c,

P

@JazzPlayer1 already said in his OP:

As @asherber noted @JazzPlayer1 is aware…:wink:

Many have desired a more robust scripting feature within Dorico. While this example is somewhat overkill and redundant (as noted in the OP) it does illustrate the point.

I had to go back and read the OP a second time – and even then found that I skimmed over a lot (simply because I recognized that it was code and didn’t need to work through it). But these examples help me understand the usefulness of scripts/scripting to do more lengthy repetitive tasks. Couple these macros with something like Stream Deck and one could save some effort for those things we may need to do frequently – especially if they are not a part of a normal workflow.

@JazzPlayer1 – Thanks for sharing.

— Jim

One thing where scripting is useful is if you want to perform an action (such as deleting all dynamics) across multiple flows. With standard commands, you’d have to do each flow in turn.

local app=DoApp.DoApp()
app:doCommand([[Edit.GoToFlow?FlowID=0]])
app:doCommand([[Edit.FilterBehaviour?FilterBehaviour=kSelect]])

numberOfFlows=3

for i=1,numberOfFlows do
	app:doCommand([[Edit.SelectAll]])
	app:doCommand([[Filter.Dynamics]])
	app:doCommand([[Edit.Delete]])
	app:doCommand([[Edit.GoToNextFlow]])
end

(You want to make sure that the Filter is Selecting, rather than De-Selecting – otherwise you’ll delete everything except dynamics!)

There’s currently no way to query the document for the number of flows, so you have to put that in by hand.
It may be possible to “try” GoToNewFlow, somehow, and then stop if there’s an error, due to no more flows – my Lua’s not that good.

From lua’s point of view, the function being executed is app:doCommand(); this function doesn’t throw any errors if the command passed in tells Dorico to go to a non-existent flow.

Thank you for the informative responses. It seems like Lua is limited to what it has access to in Dorico, and is acting as a command dispatcher. If it was possible to use something like:

score = app.currentScore()

for each in score.dynamics do
    if each.type == "mf" then
        each.delete()
    end
end

…then wow. Imagine what you could do with other objects. Again, not a feature request, but an observation. It is above my skill level, but it is something comparable to scripting in Blender, or Davinci Resolve. Imagine if you had more at your fingertips. For example if you wanted to move all text up/down/left/right by 1 or 2 points, then scripting would truly unleash a lot.

The fact that Dorico allows us to make these macros is hugely impressive and useful. Circling back to my original post - I have found Dorico to be incredible as it is, and the scripting macros are truly impressive… but sledgehammer to swat a fly :slight_smile: - maybe. But fun, it is.

Thank you for the fun discussion!