Class ScriptParameters

java.lang.Object
qupath.lib.scripting.ScriptParameters

public class ScriptParameters extends Object
Class that stores key information that is useful for running scripts.
Since:
v0.4.0
Author:
Pete Bankhead
  • Method Details

    • getFile

      public File getFile()
      Get the file where the script is located. This can return null if the script is purely in-memory.

      Note that if it is not null, the contents of the file do not have to match the result of getScript(), e.g. if the script has unsaved changes. It can nevertheless be helpful to know the location of the file to handle relative paths, if required.

      Returns:
      See Also:
    • getScript

      public String getScript()
      Get the text of the script. If this has not been set explicitly, the script is read from getFile(). If there is no script and no valid file, a RuntimeException will be thrown.
      Returns:
    • getProject

      public Project<?> getProject()
      Get the current project that should be used with the script. This may be null.
      Returns:
    • getImageData

      public ImageData<?> getImageData()
      Get the current ImageData that should be used with the script. This may be null.
      Returns:
    • getBatchSize

      public int getBatchSize()
      Get the number of images being batch processed, or 1 if just a single image is being processed.

      This is useful in combination with getBatchIndex() to write scripts that (for example) can adapt to whether they are the first or last to run in a batch.

      Returns:
      See Also:
    • getBatchIndex

      public int getBatchIndex()
      Get the index of the current image for batch processing, where 0 is the first and getBatchSize() - 1 is the last.

      This is useful in combination with getBatchSize() to write scripts that (for example) can adapt to whether they are the first or last to run in a batch.

      Returns:
      See Also:
    • getBatchSaveResult

      public Boolean getBatchSaveResult()
      Get whether changes to the image data should be saved.
      Returns:
      true if changes should be saved after running the script, false if they should not or if it is unknown
    • getArgs

      public String[] getArgs()
      Get an optional array of string arguments passed to the script.
      Returns:
    • getWriter

      public Writer getWriter()
      Get the main writer for script output.
      Returns:
    • getErrorWriter

      public Writer getErrorWriter()
      Get the error writer for script output.
      Returns:
    • getDefaultImports

      public List<Class<?>> getDefaultImports()
      Get default imports that should be included with the script, where possible. Not all languages may support adding default imports.

      The purpose of this is to make scripting easier and more intuitive, resembling a macro language and without a need for the user to know much about QuPath's classes.

      Returns:
      See Also:
    • useCompiled

      public boolean useCompiled()
      Request that any script should be compiled before being evaluated, and previously compiled versions reused when possible.

      This is not always supported, but where it is it may improve performance if the same script is evaluated many times. It may also mean that any errors are caught earlier.

      Returns:
    • doUpdateHierarchy

      public boolean doUpdateHierarchy()
      Request whether to fire an update event for the object hierarchy, if an image data object is available.

      The purpose of this is to avoid requiring the caller to fire a hierarchy update as boilerplate at the end of a script.

      Returns:
    • getDefaultStaticImports

      public List<Class<?>> getDefaultStaticImports()
      Get default static imports that should be included with the script, where possible. Not all languages may support adding default imports.

      The purpose of this is to make scripting easier and more intuitive, resembling a macro language and without a need for the user to know much about QuPath's classes.

      Returns:
      See Also:
    • builder

      public static ScriptParameters.Builder builder()
      Create a new builder for ScriptParameters.
      Returns: