Difference between revisions of "Documentation/Nightly/Developers/FAQ/Python Scripting"
Line 34: | Line 34: | ||
renderer = slicer.app.layoutManager().threeDWidget(0).threeDView().renderWindow().GetRenderers().GetFirstRenderer() | renderer = slicer.app.layoutManager().threeDWidget(0).threeDView().renderWindow().GetRenderers().GetFirstRenderer() | ||
</pre> | </pre> | ||
+ | |||
+ | == Should I used 'old style' or 'new style' python classes in my scripted module == | ||
+ | |||
+ | When python classes have no superclass specified they are 'old style' as described here [http://docs.python.org/2/reference/datamodel.html#new-style-and-classic-classes]. | ||
+ | |||
+ | In general it doesn't matter for the classes in a scripted module, since they won't be subclassed either old or new style should be the same. | ||
+ | |||
+ | For other python code in slicer where you might be subclassing, it's better to use new style classes. See the class hierarchies in the [https://github.com/Slicer/Slicer/tree/master/Modules/Scripted/EditorLib EditorLib] and the [https://github.com/Slicer/Slicer/tree/master/Modules/Scripted/DICOM/DICOMLib DICOMLib] for examples. |
Revision as of 21:06, 4 July 2013
Home < Documentation < Nightly < Developers < FAQ < Python Scripting
For the latest Slicer documentation, visit the read-the-docs. |
Contents
Python Scripting
How to save an image/volume using python ?
The module slicer.util
provides methods allowing to save either a node or an entire scene:
- saveNode
- saveScene
For more details see:
- https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/util.py#L229-267
- https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/tests/test_slicer_util_save.py
How to assign a volume to a Slice view ?
Assuming the MRHead
sample data has been loaded, you could do the following:
red_logic = slicer.app.layoutManager().sliceWidget("Red").sliceLogic() red_cn = red_logic.GetSliceCompositeNode() red_logic.GetSliceCompositeNode().SetBackgroundVolumeID(slicer.util.getNode('MRHead').GetID())
Discussion: http://slicer-devel.65872.n3.nabble.com/Assign-volumes-to-views-tt4028694.html
How to access vtkRenderer in Slicer 3D view ?
renderer = slicer.app.layoutManager().threeDWidget(0).threeDView().renderWindow().GetRenderers().GetFirstRenderer()
Should I used 'old style' or 'new style' python classes in my scripted module
When python classes have no superclass specified they are 'old style' as described here [1].
In general it doesn't matter for the classes in a scripted module, since they won't be subclassed either old or new style should be the same.
For other python code in slicer where you might be subclassing, it's better to use new style classes. See the class hierarchies in the EditorLib and the DICOMLib for examples.