Jupyter notebook

I am using Jupyter notebook to manage 3D slicer.
I am trying to control 3D slicer using python commands to automate the use of one Module.
I want to edit the buttons of the module so that I can insert the data from Jupyter. For example, when it says insert Input volume, instead of using the 3D slicer GUI, use python commands.
Can anyone help me with this, thank you!!

I would recommend to start with the Scripting and module development tutorial and then check out the Python FAQ for information on how to use CLI and Loadable modules from Python scripting. You can also find many examples in the script repository and in the modules section of the developer manual and in Python-scripted module tests. Since all these documentations are indexed by search engines, you can also google any question that you have. If you don’t find answers to any specific question (e.g., how to access a certain feature of certain module from a Python script) then you can ask it here.

1 Like

Thank you for your answer Andras, I am going to check all the provided information

Hi. I couldnt find the solution to my problem.
I am going to explain it better. I am using the a module and I want to automate the process.
For example, in this box I need to choose “Create new volume”. Do you know if there is any python code I can write instead of having to click it with the mouse.

If the YourExtension you want to automate has a YourExtensionLogic(ScriptedLoadableModuleLogic) class then you would need to find the settable parameters in that class.

Example: This code sets some necessary things in the LungCTAnalyzer extension logic from a Python script.

import LungCTAnalyzer

from LungCTAnalyzer import LungCTAnalyzerTest
from LungCTAnalyzer import LungCTAnalyzerLogic

logic = LungCTAnalyzerLogic()

# loadedVolumeNode and loadedMaskNode were created before
logic.inputVolume = loadedVolumeNode
logic.inputSegmentation = loadedMaskNode

logic.rightLungMaskSegmentID = loadedMaskNode.GetSegmentation().GetSegmentIdBySegmentName("right lung")
logic.leftLungMaskSegmentID = loadedMaskNode.GetSegmentation().GetSegmentIdBySegmentName("left lung")
logic.detailedSubsegments = True
logic.shrinkMasks = False
logic.countBullae = False

When ready, you would


to do the actual work.

Thank you for your answer.

I am trying to use SlicerIGT (SegmentationUnet module) but there is no SlicerIGTLogic class, do you know any other way to achieve this?

Gee this module is complicated. Could maybe @Sunderlandkyl or @lassoan provide a starting point for Isabella?

SlicerIGT is an extension. There is no logic for an extension but only modules have logic classes. SegmentationUNet module has a logic class - see here.