Skip to content

Commit cb78c24

Browse files
Add parameter so that globals can be passed directly
This is necessary as calling globals from inside the method lead to no variables from the call time.
1 parent 72fd4ed commit cb78c24

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/imcflibs/imagej/misc.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,9 @@ def run_imarisconvert(file_path, pixel_calibration=None, output_folder=""):
740740
timed_log("Error converting [%s]: %d" % (file_path, result))
741741

742742

743-
def save_script_parameters(destination, save_file_name="script_parameters.txt"):
743+
def save_script_parameters(
744+
destination, save_file_name="script_parameters.txt", script_globals=None
745+
):
744746
"""Save all Fiji script parameters to a text file.
745747
746748
Parameters
@@ -749,6 +751,9 @@ def save_script_parameters(destination, save_file_name="script_parameters.txt"):
749751
Directory where the script parameters file will be saved.
750752
save_file_name : str, optional
751753
Name of the script parameters file, by default "script_parameters.txt".
754+
script_globals : dict, optional
755+
The globals dictionary from the Fiji script, default None.
756+
Must be passed explicitly as ``globals()`` from the script.
752757
753758
Notes
754759
-----
@@ -758,9 +763,15 @@ def save_script_parameters(destination, save_file_name="script_parameters.txt"):
758763
The following parameters are excluded:
759764
- Parameters explicitly declared with `style="password"` are ignored.
760765
- Runtime keys (e.g. 'SJLOG', 'COMMAND', 'RM') are also skipped.
766+
767+
Examples
768+
--------
769+
In a Fiji script, you can call this function as follows to save the parameters:
770+
save_script_parameters(destination="params.txt", script_globals=globals())
761771
"""
762-
# Get the ScriptModule object from globals made by Fiji
763-
module = globals().get("org.scijava.script.ScriptModule")
772+
# script_globals must be passed explicitly as globals() from the script.
773+
g = script_globals if script_globals is not None else {}
774+
module = g.get("org.scijava.script.ScriptModule")
764775
if module is None:
765776
timed_log("No ScriptModule found - skipping saving script parameters.")
766777
return

0 commit comments

Comments
 (0)