Grid/Collection stitching of user-defined folder

Hi, I’m a beginner to ImageJ. I’m trying to write a macro to stitch images in a folder using the Grid/Collection Stitching plugin in Fiji. The following macro doesn’t seem to work in accepting a user-defined userDirectory. I’m trying to avoid hard-coding the folder so that the macro can be used flexibly for any user-prompted folder. Any tips?

userDirectory= getDirectory("Choose input directory");
run("Grid/Collection stitching", "type=[Sequential Images] order=[All files in directory] directory=userDirectory Both output_textfile_name=TileConfiguration.txt fusion_method=[Linear Blending] regression_threshold=0.30 max/avg_displacement_threshold=2.50 absolute_displacement_threshold=3.50 frame=1 computation_parameters=[Save memory (but be slower)] image_output=[Fuse and display]");

Error message:
Stitching internal version: 1.2
ERROR: ‘userDirectory/’ is not a directory. stop.
ERROR: Error during tile discovery, or invalid grid type. Aborting.

You need to specify the directory as follows in your case:

run("Grid/Collection stitching", "........... 
directory="+userDirectory+"..........."

Since you specify the directory as a variable it needs to be excluded from the fixed specifications of the macro command.

Works perfectly now! Thanks a lot.
Is the use of +varName+ a more general feature of macro? Need to use + to allow use of variables inside the macro command?

This is called String Concatenation and it’s a common concept in virtually every programming language.