ImageJ: Ask input n times using Script Parameters?

324 views Asked by At

I am trying to write a Macro in IJ1 which would ask the user:

  • the number of event they want to record
  • to name those events

I started using Script Parameters as follow:

// @ Integer (label="How many events do you want to record ?", min=1, max=50, value=1, persist=false) events

for (event=1; event<=events; event++) {  
    mLabel = "Name event number " + event + ":";  
    varname = "event" + event;  
    // @ String (label="mLabel") varname  
    print(varname);  
}

This doesn't work as it doesn't ask for the String. And even if it does, I guess it won't be very elegant as it would pop up a window to ask a Name n times (if 50, it'll be a nightmare...)

Ultimately, I want:

  • Box ask Number of Event
  • Answer is 3
  • Box ask Name of Event1, Event2, Event3

I would be really glad to have any help ! Thank you in advance !

1

There are 1 answers

0
aRnim Jenett On

When writing macros it is very useful to have the list of macros functions open https://imagej.net/developer/macro/functions.html

This should do the trick:

defaultname="event";
events=getNumber("How many events shall be run", 0);
for (event=1; event<=events; event++) {
    eventname=getString("Please define name of event "+event+":", defaultname+event);
    print(eventname);
}