Statement cannot begin with #

I cannot use parameters in the macro code.
For below example:
//test code
//test comment
#@ String name

print(“Hello” + name);

It works well when I run the code but when I debug macro in clipboard it throws error stating statement cannot begin with #. Can someone help?

HI @arindam.90,

Welcome to the forum

I tested your script and it worked for me. Could you detail the version of FIJI you are using?

I remember a long thread about that here. Maybe there might be something to help you within.

Yes I checked that thread. I am using ImageJ 1.52p.
The code works well when I run the macro; however when I debug it using clipboard it throws mentioned error.

ImageJ 2.0.0-rc-69/1.52p; java 1.8.0_172 [64-bit]

If you use Plugins-Macro-Run Macro does it work?

Oh sorry, I read your first post too quickly and missed your were using it in debug mode.

I can confirm I seem to get the same behaviour as you get, including not being able to use it through Run Macro.

This thread seems relevant

Without parameter this whole idea is not useful for me :frowning: Can you suggest any other better idea to run a macro from other programs (C# / Java) by parameter passing (headless) so that we can use this for automated analysis?

@arindam.90 Have you already read over this page?

If not, give it a look.

And could you explain what you mean by “when I debug macro in clipboard”? I would like to reproduce the problem, but I am not sure how.

Edit: Oh, I see you explained a bit more in the other thread. I have moved those posts over to this topic, to consolidate the discussion.

In my case a very simple macro with parameter (#@ String name as example) does not run using run macro. I get error that statement cannot start with #. Can someone help? I need to run ImageJ macro called from other java, .net based applications where I can achieve multithreading. But parameter passing is not working at all. If I edit the macro in editor and run it then it runs well. Seems to be a bug.

Strangest part is when I use Plugin->Edit Macro->Run option the same macro runs well without any issue and provides desired output. But if I just use Run Macro or use the same code in clipboard in debugger it does not work!

Version being used is:
ImageJ 2.0.0-rc-69/1.52p; java 1.8.0_172 [64-bit]

also tried it in
mageJ 2.1.0/1.53c; result is same…

You want to use Run Macro because you need access to a debugger, and the Script Editor lacks the needed debugging features? Do I understand correctly?

If so, see this issue on GitHub:

Unfortunately, no one currently has bandwidth to work on it. But you can follow that issue to hear about any updates in the future.

1 Like

Surely I will keep an eye. But why the basic parameter passing isn’t working? I really need some clue on it. What am I doing wrong here? Can someone please help?
The issue is about passing parameters to a macro and executing it…

My issue has been resolved. Indeed it is working, not from debugger/clipboard but when I run all macros with parameters are working. The root cause of my issue was I had space in macro file name (something with space.ijm). Surprisingly in ImageJ if you pass parameters with spaces in a string it does not work. Have you also noticed this issue? The moment I changed the file name and replaced space with underscore everything went fine :slight_smile:

1 Like