Hi,
I'm running into a couple of issues with the macro language that seem to be bugs to me: 1) Dialog.addChoice("Label", array, default) doesn't set default value, but selects the first array item macro "Test" { values = newArray(10, 100, 1000); Dialog.create("Test"); Dialog.addChoice("Label", values, 2); // 1000 expected, 10 given Dialog.show(); } 2) Returning a string from a function doesn't always work: macro "Test" { print(returnStringBroken("broken")); print(returnStringWorking("working")); function returnStringBroken(value) { return value + " example"; // breaks: Number or numeric function expected } function returnStringWorking(value) { return "" + value + " example" ; // works } } Cheers, Louis Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629. The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
hi,
no bug but: Dialog.addChoice("Label", values, 2); the default value 2 is not in your array, so it takes the first value of your array. If you want 1000 as default: values = newArray(10, 100, 1000); Dialog.create("Test"); Dialog.addChoice("Label", values, 1000); for your second point: '+' as two meanings: either the mathematical operation or string concatenation, depending on the first term. So if you have value+something, it tries to sum and doesn't succeed to add a string to a number. when you do first a string+someting, it will convert to a string and concatenate. So the trick in your case is to do as in the second example, with an empty string first, to say you want to concatenate otherwise : return *toString(number)+" example"; * cheers,* * jean-philippe Grossier* * 2013/4/16 Louis Wolf <[hidden email]> > Hi, > > I'm running into a couple of issues with the macro language that seem to > be bugs to me: > > 1) Dialog.addChoice("Label", array, default) doesn't set default value, > but selects the first array item > > macro "Test" { > values = newArray(10, 100, 1000); > > Dialog.create("Test"); > Dialog.addChoice("Label", values, 2); // 1000 expected, > 10 given > Dialog.show(); > } > > > 2) Returning a string from a function doesn't always work: > > macro "Test" { > print(returnStringBroken("broken")); > print(returnStringWorking("working")); > > function returnStringBroken(value) { > return value + " example"; // > breaks: Number or numeric function expected > } > > function returnStringWorking(value) { > return "" + value + " example" ; > // works > } > } > > Cheers, > Louis > > > > Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het > handelsregister onder nummer 41055629. > The Radboud University Nijmegen Medical Centre is listed in the Commercial > Register of the Chamber of Commerce under file number 41055629. > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Louis Wolf
Hello,
If I remember right the default in *Dialog.addChoice("Label", items, default) *is the default value not the index of the value in the list. So you should use 1000 instead of 2. In the second case the problem is not the returning of a string from a function. It is just the statement value + " example" that poses a problem. I think that if the interpreter reads a number first he interprets + as a numerical addition while when he reads a string first he interprets it as string concatenation. Volker On 04/16/2013 10:43 AM, Louis Wolf wrote: > Hi, > > I'm running into a couple of issues with the macro language that seem to be bugs to me: > > 1) Dialog.addChoice("Label", array, default) doesn't set default value, but selects the first array item > > macro "Test" { > values = newArray(10, 100, 1000); > > Dialog.create("Test"); > Dialog.addChoice("Label", values, 2); // 1000 expected, 10 given > Dialog.show(); > } > > > 2) Returning a string from a function doesn't always work: > > macro "Test" { > print(returnStringBroken("broken")); > print(returnStringWorking("working")); > > function returnStringBroken(value) { > return value + " example"; // breaks: Number or numeric function expected > } > > function returnStringWorking(value) { > return "" + value + " example" ; // works > } > } > > Cheers, > Louis > > > > Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629. > The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629. > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Volker, thanks for your reply.
> If I remember right the default in > *Dialog.addChoice("Label", items, default) > *is the default value not the index of the value in the list. So you > should use 1000 instead of 2. Nope, I don't think that is the problem. I've also tried entering the actual value in Dialog.addChoice. It is simply ignored, the first item shows up (I would actually expect an error if you put something in there that's not in the values array). > In the second case the problem is not the returning of a string from a > function. It is just the statement value + " example" that poses a > problem. I think that if the interpreter reads a number first he > interprets + as a numerical addition while when he reads a string first > he interprets it as string concatenation. It must be something like that, but not exactly. Because then it should work if "value" contains a string. But the example code I provide, which indeed contains a string, still breaks unfortunately. The code seems to interpret _every_ variable as a number. -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Volker Baecker Sent: Tuesday, April 16, 2013 11:36 AM To: [hidden email] Subject: Re: Macro Language Issues Hello, If I remember right the default in *Dialog.addChoice("Label", items, default) *is the default value not the index of the value in the list. So you should use 1000 instead of 2. In the second case the problem is not the returning of a string from a function. It is just the statement value + " example" that poses a problem. I think that if the interpreter reads a number first he interprets + as a numerical addition while when he reads a string first he interprets it as string concatenation. Volker On 04/16/2013 10:43 AM, Louis Wolf wrote: > Hi, > > I'm running into a couple of issues with the macro language that seem to be bugs to me: > > 1) Dialog.addChoice("Label", array, default) doesn't set default value, but selects the first array item > > macro "Test" { > values = newArray(10, 100, 1000); > > Dialog.create("Test"); > Dialog.addChoice("Label", values, 2); // 1000 expected, 10 given > Dialog.show(); > } > > > 2) Returning a string from a function doesn't always work: > > macro "Test" { > print(returnStringBroken("broken")); > print(returnStringWorking("working")); > > function returnStringBroken(value) { > return value + " example"; // breaks: Number or numeric function expected > } > > function returnStringWorking(value) { > return "" + value + " example" ; // works > } > } > > Cheers, > Louis > > > > Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629. > The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629. > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629. The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On 04/16/2013 02:54 PM, Louis Wolf wrote:
> Hi Volker, thanks for your reply. > >> If I remember right the default in >> *Dialog.addChoice("Label", items, default) >> *is the default value not the index of the value in the list. So you >> should use 1000 instead of 2. > Nope, I don't think that is the problem. I've also tried entering the actual value in Dialog.addChoice. It is simply ignored, the first item shows up (I would actually expect an error if you put something in there that's not in the values array). You are right, it does not work with numbers. It works ok with strings. So on a practically level you can use strings and conversions. > >> In the second case the problem is not the returning of a string from a >> function. It is just the statement value + " example" that poses a >> problem. I think that if the interpreter reads a number first he >> interprets + as a numerical addition while when he reads a string first >> he interprets it as string concatenation. > It must be something like that, but not exactly. Because then it should work if "value" contains a string. But the example code I provide, which indeed contains a string, still breaks unfortunately. The code seems to interpret _every_ variable as a number. > > > -----Original Message----- > From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Volker Baecker > Sent: Tuesday, April 16, 2013 11:36 AM > To: [hidden email] > Subject: Re: Macro Language Issues > > Hello, > If I remember right the default in > *Dialog.addChoice("Label", items, default) > *is the default value not the index of the value in the list. So you > should use 1000 instead of 2. > > In the second case the problem is not the returning of a string from a > function. It is just the statement value + " example" that poses a > problem. I think that if the interpreter reads a number first he > interprets + as a numerical addition while when he reads a string first > he interprets it as string concatenation. > > Volker > On 04/16/2013 10:43 AM, Louis Wolf wrote: >> Hi, >> >> I'm running into a couple of issues with the macro language that seem to be bugs to me: >> >> 1) Dialog.addChoice("Label", array, default) doesn't set default value, but selects the first array item >> >> macro "Test" { >> values = newArray(10, 100, 1000); >> >> Dialog.create("Test"); >> Dialog.addChoice("Label", values, 2); // 1000 expected, 10 given >> Dialog.show(); >> } >> >> >> 2) Returning a string from a function doesn't always work: >> >> macro "Test" { >> print(returnStringBroken("broken")); >> print(returnStringWorking("working")); >> >> function returnStringBroken(value) { >> return value + " example"; // breaks: Number or numeric function expected >> } >> >> function returnStringWorking(value) { >> return "" + value + " example" ; // works >> } >> } >> >> Cheers, >> Louis >> >> >> >> Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629. >> The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629. >> >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629. > The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Volker Baecker
Ah, cool. Thanks :)
-----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Volker Baecker Sent: Tuesday, April 16, 2013 11:36 AM To: [hidden email] Subject: Re: Macro Language Issues Hello, If I remember right the default in *Dialog.addChoice("Label", items, default) *is the default value not the index of the value in the list. So you should use 1000 instead of 2. In the second case the problem is not the returning of a string from a function. It is just the statement value + " example" that poses a problem. I think that if the interpreter reads a number first he interprets + as a numerical addition while when he reads a string first he interprets it as string concatenation. Volker On 04/16/2013 10:43 AM, Louis Wolf wrote: > Hi, > > I'm running into a couple of issues with the macro language that seem to be bugs to me: > > 1) Dialog.addChoice("Label", array, default) doesn't set default value, but selects the first array item > > macro "Test" { > values = newArray(10, 100, 1000); > > Dialog.create("Test"); > Dialog.addChoice("Label", values, 2); // 1000 expected, 10 given > Dialog.show(); > } > > > 2) Returning a string from a function doesn't always work: > > macro "Test" { > print(returnStringBroken("broken")); > print(returnStringWorking("working")); > > function returnStringBroken(value) { > return value + " example"; // breaks: Number or numeric function expected > } > > function returnStringWorking(value) { > return "" + value + " example" ; // works > } > } > > Cheers, > Louis > > > > Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629. > The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629. > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629. The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Jean-Philippe Grossier
Hi
I am beginner in ImageJ, sorry if I am digging up a dead topic. I have in a emergency situation that have to ask it. I am trying to analyze a sequence of images of few particles that I have to write the position of this particles in text files. I am using this macro but in the save as part I ma getting an error. please help if you know whats going on! num = getNumber("number of images : ",100) ; for(id=num-1; id >= 0 ;id--) { if ( id < 10) open("/Users/zjalilvand/Desktop/test/images000"+id+".tif"); if ( id > 9 && id < 100) open("/Users/zjalilvand/Desktop/test/images00"+id+".tif"); if ( id > 99) open("/Users/zjalilvand/Desktop/test/images0"+id+".tif"); run("Analyze Particles...", "size=100-1000 circularity=0.0-1.00 show=Nothing display clear slice"); saveAs(“measurements”, ”Users/zjalilvand/Desktop/test/results/Results"+id+".txt"); close; } |
Free forum by Nabble | Edit this page |