diff --git a/_pages/scripting/interpreter.md b/_pages/scripting/interpreter.md index c108d063a6..7ce64d3345 100644 --- a/_pages/scripting/interpreter.md +++ b/_pages/scripting/interpreter.md @@ -12,11 +12,52 @@ Start it via {% include bc path='Plugins|Scripting|Script Interpreter'%} or by t ![Script_Interpreter.png](/media/scripting/script-interpreter.png) -## Usage +## Usage Examples -### Get the active dataset +The examples below are written in "C-like" syntax. They should work as-is e.g. in [Groovy](groovy), [Jython](jython), and [JavaScript](javascript), but will need adjustment for languages like [Clojure](clojure) whose syntax diverges more from C. -### Run an op +| Operation | Code | +|---------------------------------|-------------------------------------------------------| +| Get the active dataset | `image = imageDisplay.getActiveDataset()` | +| Run an op | `blurred = op.run("filter.gauss", image, 5)` | +| Quick display (no metadata!) | `ui.show("Blurred", blurred)` | +| Wrap image to dataset | `ds = dataset.create(blurred)` | +| Get dataset dimensionality | `ds.numDimensions()` | +| Get length of dim #d | `ds.dimension(d)` | +| Get dim #d axis type | `ds.axis(d).type()` | +| Override dim #d axis type | `ds.axis(d).setType(Axes.CHANNEL)` | +| Blend channels when displaying | `ds.setCompositeChannelCount(3)` | +| Wrap dataset to data view | `dv = imageDisplay.createDataView(ds); dv.rebuild()` | +| Set color table for channel #0 | `dv.setColorTable(ColorTables.MAGENTA, 0)` | +| Set color table for channel #1 | `dv.setColorTable(ColorTables.GREEN, 1)` | +| Set color table for channel #2 | `dv.setColorTable(ColorTables.BLUE, 2)` | +| Wrap data view to display | `disp = display.createDisplay("Blurred", dv)` | +| Get a display by title | `disp = display.getDisplay("Blurred")` | +| Get `DataView` from display | `dv = disp[0]` | +| Get dataset from `DataView` | `ds = dv.getData()` | + +You can import `Axes` from `net.imagej.axis`, and `ColorTables` from `net.imagej.display`. + +See the [ImageJ2 Tutorials](https://github.com/imagej/tutorials) for more recipes. + +## Inspecting API of an Object + +The script interpreter does not yet have tab completion. :-( But you can using the following (Python) function to list the methods of an object: +```python +def methods(obj, prefix=""): + return "\n".join(row["name"] + "(" + row["arguments"] + ") -> " + row["returns"] for row in notebook.methods(obj, prefix)) +``` +E.g.: +``` +>>> methods(imageDisplay, "getActive") +getActiveDataset() -> net.imagej.Dataset +getActiveDataset(net.imagej.display.ImageDisplay) -> net.imagej.Dataset +getActiveDatasetView() -> net.imagej.display.DatasetView +getActiveDatasetView(net.imagej.display.ImageDisplay) -> net.imagej.display.DatasetView +getActiveImageDisplay() -> net.imagej.display.ImageDisplay +getActivePosition() -> net.imagej.Position +getActivePosition(net.imagej.display.ImageDisplay) -> net.imagej.Position +``` ## Issues diff --git a/media/scripting/script-interpreter.png b/media/scripting/script-interpreter.png index 6b7ba99009..34193e7c04 100644 Binary files a/media/scripting/script-interpreter.png and b/media/scripting/script-interpreter.png differ