getArgument() equivalent for .py vs .ijm script



if I run a script from within another script
using IJ.runMacroFile(scriptName,“arg”)

if scriptName is a .ijm file in that script
I can get “arg” using getArgument()

However, I want to use a .py file
and I thought I should be able to get "arg"
but this returns None i.e. null

How can I access “arg” from a python script?


Not sure if I understand your question – do you want to run a python script within another python script?

If so, the Macro_Runner class seems to have a runPython method that might help.


public static java.lang.String runPython(java.lang.String script, java.lang.String arg)

Runs a Python script on the current thread, passing a string argument, which the script can retrieve using the getArgument() function. Returns, as a string, the value of the variable ‘result’. For example, a Python script containing the line “result=123” will return the string “123”. Uses the plugin at to run the script.


To try and clarify,
I want to pass a variable from a line of script run in an action bar script </macro) and pass it on to to a python script which I am wanting to run.
The script in the action action bar is IJ1 macro language.

And if the script I am calling is a IJ1 script I can use getArgument() to get the arg .

However, if the script I am calling is, then getArgument is not recognized. I get the error "name ‘getArgument’ is not defined”.
So I need to import a method that properly defines getArgument in my .py script.

And I don’t think the runPython method does this. That instigates the calling of the script in the sending script.

I want the appropriate class import in the .py script to define getArgument


Dear @MLNonet,
I usually do something like that:

  1. create a python script, for example that does a blur with a radius and variance filter with anotther radius as inputs
#@Integer(label="blur radius", value = 2) rad_blur
#@Integer(label="variance radius", value = 2) rad_variance

from ij import IJ
imp = IJ.getImage();, "Gaussian Blur...", "sigma="+str(rad_blur));, "Variance...", "radius="+str(rad_variance));
  1. save it in the Fiji plugins folder

  2. then the macro will be:

run("Blobs (25K)"); //open a sample image, since in the python scripton I have imp=IJ.getImage()

run("py with args","rad_blur=10 rad_variance=3");

Using scriptparameters it’s not recorded by itself, but it works.
If I remember well if you use in python GenericDialog ( if you run the macro recorder also the parameters will be automatically recorded.

I hope it helps,
have a nice day