Test number of input layers and stop filter execution

Hello,

Is it possible to test the number of input layers (inside GIMP GMIC plugin filter execution) for a particular number and stop execution if it is different? I optionally want to display an error message.

Something like:
if (count(layers) <> 3) // Test the number of input layers
MsgBox(“Number of input layers is wrong!”); // Display error message
exit(0); // Stop execution of the current filter

Thanks for help.

Yes, you can do something like:

if $!<2 gui_print_preview "Warning:",,"This filter requires at least two input layers to work properly." return fi

where $! refers to the number of images in the stack (gimp “layers” become images in gmic).

1 Like

Thanks. Do I need to use a “long” else statement because it is not possible to use early terminating like “exit(0)”?

Sorry I should have mentioned - the early termination is return and you can use that simply within an if ... fi block without problem

1 Like

My mistake. My old brain filtered out a familiar C/C ++ “return” command :slight_smile:

1 Like

quit is also a more violent way of terminating (you are sure the interpreter quits, while return just returns from the current command).