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: MyCmd.class, true )

And MyCmd has a 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 );;

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?

1 Like

Hi @ctrueden,
Do you think this is something that could implemented in a not so distant future?
I just came across another use case in one of my projects…
I totally understand if your answer is “no”, because I do realise we all have limited resources to work on stuff…

1 Like