Remove 3D view axis labels in python script

Hi, I’m trying to save images of a volume render via a python script and I would like to toggle off the axis labels but I’m unable to do so.

I’ve searched inside various objects, layoutManager.threeDWidget(0).threeDView() and layoutManager.threeDWidget(0).threeDView().renderWindow().GetRenderers().GetFirstRenderer(), for example but I can’t find a way.

Here is my code so far:

fname_vol = 'T1.mgz'
loadedVolumeNode = slicer.util.loadVolume(fname_vol)
volumeNode = slicer.util.getNode('T1')

volRenLogic = slicer.modules.volumerendering.logic()
displayNode = volRenLogic.CreateDefaultVolumeRenderingNodes(volumeNode)

layoutManager = slicer.app.layoutManager()
threeDView = layoutManager.threeDWidget(0).threeDView()
renderWindow = threeDView.renderWindow()
renderer = renderWindow.GetRenderers().GetFirstRenderer()
renderWindow.Render()

views_names = ('Anterior', 'Left', 'Right')
views_att = (ctk.ctkAxesWidget().Anterior, ctk.ctkAxesWidget().Left, ctk.ctkAxesWidget().Right)

for v, a in zip(views_names, views_att):
    threeDView.lookFromViewAxis(a)
    renderWindow.SetAlphaBitPlanes(1)
    wti = vtk.vtkWindowToImageFilter()
    wti.SetInputBufferTypeToRGBA()
    wti.SetInput(renderWindow)
    writer = vtk.vtkPNGWriter()
    writer.SetFileName(test_%s.png" % v)
    writer.SetInputConnection(wti.GetOutputPort())
    writer.Write()

Any help would be very appreciated, cheers,

Operating system: Ubuntu 18
Slicer version: 4.10.2

Does this help?

v = slicer.mrmlScene.GetNodeByID('vtkMRMLViewNode1')
v.SetAxisLabelsVisible(True)
# or
v.SetAxisLabelsVisible(False)
1 Like

It worked perfectly. Thanks a lot!