Re: common functions / installing multiple macro files
Posted by
Benjamin Gilbert on
Aug 02, 2009; 8:45pm
URL: http://imagej.273.s1.nabble.com/common-functions-installing-multiple-macro-files-tp3691526p3691528.html
Thanks for the very clear reply. I learnt how to store global
variables from an earlier post to the list using call("ij.Prefs.get",
<key>, <value>) ... but perhaps a single toolset would be a simpler
approach!
Is there likely to be support for multivariate fit functions in the
near future? I would like to fit a 2D polynomial to make an image
background.
many thanks
ben
At 4:18 PM -0400 8/1/09, Wayne Rasband wrote:
>On Jul 31, 2009, at 10:00 AM, Benjamin Gilbert wrote:
>
>>I have a collection and macros and functions in a single macro text file. I
>>would now like to translate these routines into a toolset, which requires
>>making a single macro file for each operation and saving it in the
>>ImageJ/plugins folder.
>>
>>The original approach allowed different macros to use common functions, but
>>it seems that an individual tool must be completely self-contained. I was
>>hoping that I could install a macro containing all common functions that
>>would be accessible to tool macros but this does not work. In general, it
>>appears that only a single macro file can be installed at a time.
>>
>>Is there a way to do this? I don't want to have multiple instances of the
>>same functions in different macro files.
>
>You can do this by adding the common functions to the macro language
>by calling the Interpreter.setAdditionalFunctions() method. Here is
>an example.
>
>Create a folder in the plugins folder named MyMacros. Add these
>three files (CommonFunctions, Macro1 and Macro2) to it:
>
> CommonFunctions.txt
>
> function f1() {
> print("f1");
> }
> function f2() {
> print("f2");
> }
>
> Macro1.ijm
>
> print("Macro1");
> f1();
> f2();
>
> Macro2.ijm
>
> print("Macro2");
> f1();
> f2();
>
>Then add this code to the StartupMacros file (Plugins>Macros>StartupMacros)
>
> macro "AutoRun" {
> path = getDirectory("plugins")+"MyMacros/CommonFunctions.txt";
> functions = File.openAsString(path);
> call("ij.macro.Interpreter.setAdditionalFunctions", functions);
> }
>
>save it and restart ImageJ. You will now have two commands (Macro1
>and Macro2) in the Plugins>MyMacros submenu implemented by macros
>that share the functions in CommonFunctions. CommonFunctions has a
>.txt extension and no underscore in the name so it does not appear
>in the Plugins>MyPlugins submenu. Macro1 and Macro2 have .ijm
>(ImageJ Macro) extensions so they do appear even though they do not
>have an underscore in the name.
>
>You may decide that it's easier and better to keep the functions and
>macros in a single file (toolset) located in the
>ImageJ/macros/toolsets folder. That way the macros and functions can
>share global variables, you can easily add keyboard shortcuts, the
>toolset can contain tools, toolbar menus and action tools as well as
>macros, and you can have multiple toolsets, selected from the ">>"
>toolbar menu.
>
>-wayne
--
Benjamin Gilbert
Scientist, Earth Science Division
Lawrence Berkeley National Laboratory
1 Cyclotron Road MS 90R1116
Berkeley, CA 94720 USA
[hidden email]
http://nanogeoscience.berkeley.eduOffice: 90 1143
Lab: 70 158
Office: 1-510 495 2748
Lab: 1-510 486 4424
Cell: 1-608 358 0194
Fax: 1-510 486 5686