Execute/Run ExecuteDat from code

I feel a little stupid for not finding the command but I want to run a Chop Execute that is set to value change but using a command somewhere else. So basically it should do the same thing as when a value changes.
I found a workaround to simulate the value change so it executes but would love to it nice and clean with a command.

Probably the command has to include the “onValueChange” since it also does not execute using the keyboard shortcut or clicking run script.

Thanks in advance for your help!!!

You can run it as a function. You’ll have to fake the previous value I guess. Will look something like this:

op(‘chopexec1’).module.onValueChange(op(‘CHOP’).chan(‘chanName’), sampleIndex, val, prev)

Faking all those arguments is the weird part, but the function will just work as if called by the system.

A nicer way to do it is to create another function that is called by onValueChange and then call THAT function instead.

Is there a reason you need to do this with code inside a Chop Execute? The Text DAT has a run() method, which will execute any code inside of it.

If it’s for testing purposes, I would just connect a button to the CHOP’s input.

I’d generally recommend against running DATs as scripts. Putting your code in functions and running those functions keeps things much more organized and flexible.

As for why you’d put it inside a CHOP execute, it’s because the goal is to run it sometimes from the execute and sometimes from script.

On looking at this again, the nicest way to achieve the goal is actually to have a separate function that the CHOP execute runs, and to call that function from script. That requires a bit more coding but is probably worth the time. Another important thing to avoid is putting the same code in two places, like both in the CHOP execute DAT and in the script… if you are trying to do the same task from both places, you should be running the same code. That way if you want to change something you don’t have to remember to do it twice.