How can I code "Execute during preview" capability in custom snap? (i.e. testing validation mode vs. run-time mode)

I have a snap, that I have developed, for which I would like to add the “Execute during preview” capability.
Can anyone provide me with java code capable of accomplishing this? I do not need the code to create the UI feature, property or variable. I just need the code to determine whether the execution process is in the validation or run-time mode.

– Del

You’ll need to implement SuggestExecutionProvider and override the executeForSuggest method for “executing” during validation.

Since you don’t need the “Execute during preview” property, the easiest approach will be to call the execute method within executeForSuggest as follows:

public void executeForSuggest() {
1 Like

@del adding @Category(snap = SnapCategory.WRITE) to the class definition will automatically expose the “Execute during preview” checkbox. As @rohithmadhavan stated, behavior can be customized with SuggestExecutionProvider.

See and

1 Like

Thank you very much for your lighting-speed responses @rohithmadhavan and @robin.

I started on @rohithmadhavan’s suggestion first and the path was very educational for me as I started to implement it. However, my question was vague in detail, and a little misdirecting, so @robin’s response was the simpler solution I was looking for. I’ve developed 4 simple snaps, but none were write snaps, so that answer was not yet obvious to me.

It’s now working like a charm, so thank you both very much!

– Del