|
7 | 7 | import subprocess |
8 | 8 | import sys |
9 | 9 | import time |
| 10 | +from org.scijava.script import ScriptModule |
10 | 11 |
|
11 | 12 | from ij import IJ # pylint: disable-msg=import-error |
12 | 13 | from ij.plugin import Duplicator, ImageCalculator, StackWriter |
@@ -701,3 +702,35 @@ def run_imarisconvert(file_path): |
701 | 702 | IJ.log("Conversion to .ims is finished.") |
702 | 703 | else: |
703 | 704 | IJ.log("Conversion failed with error code: %d" % result) |
| 705 | + |
| 706 | + |
| 707 | +def save_script_parameters(destination, save_file_name="script_parameters.txt"): |
| 708 | + """Save all Fiji script parameters to a text file. |
| 709 | +
|
| 710 | + Parameters |
| 711 | + ---------- |
| 712 | + destination : str |
| 713 | + Directory where the script parameters file will be saved. |
| 714 | + save_file_name : str, optional |
| 715 | + Name of the script parameters file, by default "script_parameters.txt". |
| 716 | + """ |
| 717 | + # Get the ScriptModule object from globals made by Fiji |
| 718 | + module = globals().get("org.scijava.script.ScriptModule") |
| 719 | + if module is None: |
| 720 | + print("No ScriptModule found- skipping saving script parameters.") |
| 721 | + return |
| 722 | + |
| 723 | + # Retrieve the input parameters from the scijava module |
| 724 | + inputs = module.getInputs() |
| 725 | + destination = str(destination) |
| 726 | + out_path = os.path.join(destination, save_file_name) |
| 727 | + |
| 728 | + # Write the parameters to output file |
| 729 | + with open(out_path, "w") as f: |
| 730 | + for key in inputs.keySet(): |
| 731 | + val = inputs.get(key) |
| 732 | + f.write("%s: %s\n" % (key, str(val))) |
| 733 | + |
| 734 | + print("Saved script parameters to: %s" % out_path) |
| 735 | + |
| 736 | + |
0 commit comments