Viewing Side by Side

Is there python code to switch the viewing panes? Before I do my segmentation, I need to set the code to display only the Coronal and Sagittal view before the segmentation and then display the 3D view along with the coronal and sagittal view after the segmentation has been complete. Does anyone know how to do this in python?

@lassoan @Sunderlandkyl @cpinter

You can find examples for all commonly used functions in the script repository. For example, custom layout creation is described here:

1 Like

Hello @lassoan,

Thank you for helping us with this project. We have one more question. When we use layout 29 (sidebyside), we get the axial and sagittal view. When we used the custom layout sidebyside code from the github to try to get the coronal and sagittal view, we get an error. We copied the code below into our module and created a custom layout ID but this did not work. How can we integrate the github sidebyside code into our module?

Can you send a github repository link to the line that fails?

1 Like

It says invalid syntax when initializing the sideBySideView:

sideBySideView =
“<layout type=“horizontal”>”
" "
" <view class=“vtkMRMLSliceNode” singletontag=“Red”>"
" <property name=“orientation” action=“default”>Sagittal"
" <property name=“viewlabel” action=“default”>R"
" <property name=“viewcolor” action=“default”>#F34A33"
" "
" "
" "
" <view class=“vtkMRMLSliceNode” singletontag=“Yellow”>"
" <property name=“orientation” action=“default”>Coronal"
" <property name=“viewlabel” action=“default”>Y"
" <property name=“viewcolor” action=“default”>#EDD54C"
" "
" "

Also, should we put this in the enter function, so it runs when we enter the module?

1 Like

You have to ad the closing tags as well: </layout> at the end, and </view> and </property> to the end of the corresponding lines.

I added my custom layouts in the file, for example:

resizableFourUpLayout = ("<layout type=\"vertical\" split=\"true\"><item><layout type=\"horizontal\" split=\"true\"><item><view class=\"vtkMRMLSliceNode\" singletontag=\"Red\"><property name=\"orientation\" action=\"default\">Axial</property><property name=\"viewlabel\" action=\"default\">R</property><property name=\"viewcolor\" action=\"default\">#F34A33</property></view></item><item><view class=\"vtkMRMLViewNode\" singletontag=\"1\"><property name=\"viewlabel\" action=\"default\">1</property></view></item></layout></item><item><layout type=\"horizontal\"><item><view class=\"vtkMRMLSliceNode\" singletontag=\"Yellow\"><property name=\"orientation\" action=\"default\">Sagittal</property><property name=\"viewlabel\" action=\"default\">Y</property><property name=\"viewcolor\" action=\"default\">#EDD54C</property></view></item><item><view class=\"vtkMRMLSliceNode\" singletontag=\"Green\"><property name=\"orientation\" action=\"default\">Coronal</property><property name=\"viewlabel\" action=\"default\">G</property><property name=\"viewcolor\" action=\"default\">#6EB04B</property></view></item></layout></item></layout>")
layoutLogic =
layoutLogic.GetLayoutNode().AddLayoutDescription(520, resizableFourUpLayout)
# # Uncomment if set on startup
1 Like

Thanks! When we run that @cpinter we still get an error on this line:


The error is: ‘NoneType’ object has no attribute ‘getParameterNode’

Do you have any ideas?

1 Like

Without seeing the context (i.e. the surrounding code), it is impossible to tell from one line what is the problem. In general this error means that the variable has not been set properly. Is it possible you want to run this line outside a module class? It would help if we saw some more code.

1 Like

Thanks, it works now!