A simple embedded programming editor for 3D Slicer, based on monaco editor.
The ScriptEditor extension provides the open-source Monaco editor as a module inside the Slicer. It supports auto-completion, and syntax highlighting and allows the scripts to be directly sent to the 3D Slicer's built-in Python console.
The most typical use case for Script Editor is to develop, debug, and execute Python scripts directly within the 3D Slicer environment. This allows users to automate tasks, create custom analyses, and enhance the functionality of 3D Slicer through scripting.
Extension Manager
by clicking on the View
menu and selecting Extension Manager
.ScriptEditor
.Install
next to the ScriptEditor
extension.Ctrl
+ F
(or click the search icon in the toolbar).Script Editor
from the list of modules.Script Editor
module, you will see a combo box labeled Script Node
.Here's an example script that can be used to load a sample volume and apply a Gaussian smoothing filter:
import SampleData
import sitkUtils
import SimpleITK as sitk
# Load sample volume
sampleVolume = SampleData.SampleDataLogic().downloadMRHead()
# Apply Gaussian smoothing
inputImage = sitkUtils.PullVolumeFromSlicer(sampleVolume)
smoothedImage = sitk.SmoothingRecursiveGaussian(inputImage, sigma=2.0)
# Push the result back to Slicer
smoothedVolume = sitkUtils.PushVolumeToSlicer(smoothedImage, name='SmoothedVolume')
slicer.util.setSliceViewerLayers(background=smoothedVolume)
print
statements to output information to the Slicer Python Interactor for debugging purposes.The Script Editor extension has undergone significant development and improvements over its versions. A previous iteration of the extension can be found in the repository at pieper/SlicerEditor.
This project was undertaken during the 3D Slicer Project Week, a collaborative event where developers and researchers work on Slicer-related projects. The specific undertaking for Script Editor was part of the 3D Slicer Project Week 41, held at MIT in 2024. The goal of this project was to create a simple and effective editor for Python scripting within 3D Slicer, leveraging the Monaco Editor for enhanced user experience.
ScriptEditor is created and made available by funding from National Science Foundation (MorphoCloud: DBI/2301405; Imageomics Institute: OAC/2118240)