I would like to use the pull down menu to run a macro that is in the same text file or a function in the same file. runMacro() requires a file on disk and trying to call a function I defined returns an error message.
For instance, based on https://imagej.nih.gov/ij/macros/CustomPopupMenu.txt, I tried the following with my function testPulldownMenu(). The other commands in the list are mostly macros in the same file. And the B&C commands works fine. Is there a way to call my own functions or macros? Any help greatly appreciated. var pmCmds = newMenu("Popup Menu", newArray("testPulldownMenu", "Prepare image for markup", "Mark Distal", "Mark Nucleus", "Add Line Segment", "Grays LUT", "Color LUT", "Brightness/Contrast...")); macro "Popup Menu" { cmd = getArgument(); run(cmd); //runMacro(cmd); } function testPulldownMenu() { print("successful"); } Michael Cammer, Sr Research Scientist, DART Microscopy Laboratory NYU Langone Health, 540 First Avenue, SK2 Microscopy Suite, New York, NY 10016 [hidden email]<mailto:[hidden email]> http://nyulmc.org/micros http://microscopynotes.com/ Voice direct only, no text or messages: 1-914-309-3270 and 1-646-501-0567 ------------------------------------------------------------ This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email. ================================= -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Privately Jan Brocher wrote to me an answer regarding how to call a function (which I really should have seen myself, but didn't...).
Make a series of if statements testing the menu items and call the function without the cmd() function!! This will solve my problem, although still interested whether there is also a way to execute a macro in the same file too. Best regards- Michael Cammer, Sr Research Scientist, DART Microscopy Laboratory NYU Langone Health, 540 First Avenue, SK2 Microscopy Suite, New York, NY 10016 [hidden email]<mailto:[hidden email]> http://nyulmc.org/micros http://microscopynotes.com/ Voice direct only, no text or messages: 1-914-309-3270 and 1-646-501-0567 ________________________________ From: Cammer, Michael <[hidden email]> Sent: Wednesday, December 16, 2020 9:44 AM Subject: calling macros or functions from within a macro [EXTERNAL] I would like to use the pull down menu to run a macro that is in the same text file or a function in the same file. runMacro() requires a file on disk and trying to call a function I defined returns an error message. For instance, based on https://urldefense.proofpoint.com/v2/url?u=https-3A__imagej.nih.gov_ij_macros_CustomPopupMenu.txt&d=DwIFAw&c=j5oPpO0eBH1iio48DtsedeElZfc04rx3ExJHeIIZuCs&r=hUBj2D5n6oKThx2L01qn8IORZb5f-ruLVXPmQ1zQNnM&m=zUpcpvpWbZ6jZkowuaZ3gC9KAxVgfawRpQPUxGIWcF0&s=5acnuUtu6HkZPmclGDNDnzbgmOuJpqCx8XjVKV5ZbQ8&e= , I tried the following with my function testPulldownMenu(). The other commands in the list are mostly macros in the same file. And the B&C commands works fine. Is there a way to call my own functions or macros? Any help greatly appreciated. var pmCmds = newMenu("Popup Menu", newArray("testPulldownMenu", "Prepare image for markup", "Mark Distal", "Mark Nucleus", "Add Line Segment", "Grays LUT", "Color LUT", "Brightness/Contrast...")); macro "Popup Menu" { cmd = getArgument(); run(cmd); //runMacro(cmd); } function testPulldownMenu() { print("successful"); } Michael Cammer, Sr Research Scientist, DART Microscopy Laboratory NYU Langone Health, 540 First Avenue, SK2 Microscopy Suite, New York, NY 10016 [hidden email]<mailto:[hidden email]> https://urldefense.proofpoint.com/v2/url?u=http-3A__nyulmc.org_micros&d=DwIFAw&c=j5oPpO0eBH1iio48DtsedeElZfc04rx3ExJHeIIZuCs&r=hUBj2D5n6oKThx2L01qn8IORZb5f-ruLVXPmQ1zQNnM&m=zUpcpvpWbZ6jZkowuaZ3gC9KAxVgfawRpQPUxGIWcF0&s=aRVmUoDNfeTRZKcHMDbdx805W9pQ1cSjUC8jqa0dgIw&e= https://urldefense.proofpoint.com/v2/url?u=http-3A__microscopynotes.com_&d=DwIFAw&c=j5oPpO0eBH1iio48DtsedeElZfc04rx3ExJHeIIZuCs&r=hUBj2D5n6oKThx2L01qn8IORZb5f-ruLVXPmQ1zQNnM&m=zUpcpvpWbZ6jZkowuaZ3gC9KAxVgfawRpQPUxGIWcF0&s=JPXvQ6NKJ2DGlitAsEcAboxhEMbU0BWv-Q3VgI0QyWg&e= Voice direct only, no text or messages: 1-914-309-3270 and 1-646-501-0567 ------------------------------------------------------------ This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email. ================================= -- ImageJ mailing list: https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.nih.gov_ij_list.html&d=DwIFAw&c=j5oPpO0eBH1iio48DtsedeElZfc04rx3ExJHeIIZuCs&r=hUBj2D5n6oKThx2L01qn8IORZb5f-ruLVXPmQ1zQNnM&m=zUpcpvpWbZ6jZkowuaZ3gC9KAxVgfawRpQPUxGIWcF0&s=VfjKRAHU949V170gmy7gQ1ELO1Lpkqex1S9kCCEUZhA&e= -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Cammer, Michael-3
> On Dec 16, 2020, at 9:44 AM, Cammer, Michael <[hidden email]> wrote:
> > I would like to use the pull down menu to run a macro that is in the same text file or a function in the same file. runMacro() requires a file on disk and trying to call a function I defined returns an error message. The following macro code, when saved as a file and installed using Plugins>Macros>Install, creates an image popup menu that with a “My Function” command that calls the function myFunction(). -wayne var pmCmds = newMenu("Popup Menu", newArray("My Function","Fire","Invert LUT")); macro "Popup Menu" { cmd = getArgument(); if (cmd=="My Function") myFunction(); else run(cmd); } function myFunction() { print("successful"); } > For instance, based on https://imagej.nih.gov/ij/macros/CustomPopupMenu.txt, I tried the following with my function testPulldownMenu(). The other commands in the list are mostly macros in the same file. And the B&C commands works fine. > > > Is there a way to call my own functions or macros? Any help greatly appreciated. > > > var pmCmds = newMenu("Popup Menu", > newArray("testPulldownMenu", "Prepare image for markup", "Mark Distal", "Mark Nucleus", "Add Line Segment", "Grays LUT", "Color LUT", > "Brightness/Contrast...")); > > macro "Popup Menu" { > cmd = getArgument(); > run(cmd); > //runMacro(cmd); > } > > function testPulldownMenu() { > print("successful"); > } -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |