Include variable in macro

Hey, everyone! I’m quite new in the whole writing scripts world and I happen to be a bit lost. I am following Robert Haase’s lectures on imagej on youtube and doing the exercises. I want to go over a whole folder with files but have problems when opening the files; therefore, I decided to open them using the bioformats plugin. The problem I encountered is that I don’t know how to include the function parameters “input” and “filename” inside the “macro script”. I attach the script and a screenshot of where I have the problem and the error I get when running the script.

Thanks in advance!

converting_tif.ijm (528 Bytes)

1 Like

Hi @anayague,

happy to hear you’re attending my lecture :slight_smile:

The error message points you with the < and > brackets to the point in line 5 where there might be something missing.

You’re code line 5 looks like this:

run("Bio-Formats", "open=["input+filename"] autoscale color_mode=Default display_metadata rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT stitch_tiles");

As mentioned in the first macro part, concatenating strings is done with the + operator. In your code line, you’re trying to concatenate these four elements: 1) "open=[", 2) input, 3) filename and 4) the rest. Thus, the + between input and filename is fine, but you need another + before input and after filename to concatenate these four strings.

Thus, your code line 5 is supposed to look like this:

run("Bio-Formats", "open=[" + input + filename + "] autoscale color_mode=Default display_metadata rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT stitch_tiles");

If you put spaces in front and after the + operator, it becomes easier to read and missing + are easier to spot - at least after some training.

Let me know how it goes and if you need further support!

Cheers,
Robert

I just tried it and worked! Thanks a lot! Really enjoying the lectures, btw :slight_smile:

Ana

1 Like