Programmatically set defaults of SciJava Command

Hi @imagejan @ctrueden @NicoKiaru @haesleinhuepf @stelfrich,

Do you know whether it is possible to programmatically set the defaults of a Command?

For example, let’s say I call a command like this:

CommandService.run( MyCmd.class, true )

And MyCmd has a parameter

@Parameter
int number

Can I set number = 5, programmatically, just before calling the CommandService?

The point is that the calling code knows already good presets and just would like to user to confirm or maybe slightly adapt these good presets.

1 Like

Great question. I don’t think it’s possible right now without writing a custom preprocessor, or doing some hacky initialization (e.g. which reads external state assigned in advance by the calling code) in the command itself.

Do you have an idea how we could augment the API to allow this?

1 Like

Maybe something like:

runnableCommand = CommandService.getRunnableCommand( MyCmd.class, true );
runnableCommand.setDefault( "number", 5 );
runnableCommand.run();

If we do something like this, one could also grant more fine grained control over many of the other things that we discussed recently, e.g.

runnableCommand.setModal( true );

or, for example,

runnableCommand.setRecordMacro( false )

What do you think?