I am a fairly new user of 3D Slicer. I was wondering if it is possible to call the “CreateModels” functions of the Slicer IGT module from a python script.
I need to create cylinder models in a more automated way, thus I wanted to combine python and Slicer IGT for this.
A more general questions: Can all the modules be called from python ?
The short answer is yes, all Slicer modules can be accessed from python.
Here’s a very long answer:
Developer Guide — 3D Slicer documentation
Self tests can be a good place to look to try to find examples of code in use. Here’s one I found which seems to use the IGT create models functionality in a basic way:
One of the most important features of the tests is that it should alert other
developers when their changes will have an impact on the behavior of your
module. For example, if a developer removes a feature that you depend on,
your test should break so they know that the feature is needed.
slicer.util.delayDisplay("Starting the test")
modelNodes = 
createModelsLogic = slicer.modules.createmodels.logic()
sphereRadius = 10.0
sphereModel = createModelsLogic.CreateSphere(sphereRadius) # watched model
toolModel = createModelsLogic.CreateNeedle(50.0, 1.5, 0.0, False)
slicer.util.delayDisplay("Set up module GUI")
mainWindow = slicer.util.mainWindow()
bwWidget = slicer.modules.breachwarning.widgetRepresentation()
bwColorPickerButton = slicer.util.findChildren(widget=bwWidget, className='ctkColorPickerButton', name='WarningColorPickerButton')
bwModelNodeCombobox = slicer.util.findChildren(widget=bwWidget, name='ModelNodeComboBox')
Here is the C++ code for the Create Models module:
SlicerIGT/vtkSlicerCreateModelsLogic.cxx at 39dfcfa3c83e07981054b6e2164c5f26552b93bb · SlicerIGT/SlicerIGT · GitHub
Those C++ functions are wrapped and accessible via python.