# Python code controls the display of a certain layer of slices in the view

**URL:** <https://discourse.slicer.org/t/python-code-controls-the-display-of-a-certain-layer-of-slices-in-the-view/34781>\
**Category:** Development\
**Tags:** python, coordinates\
**Created:** [March 8, 2024, 3:05pm UTC](https://discourse.slicer.org/t/python-code-controls-the-display-of-a-certain-layer-of-slices-in-the-view/34781 "2024-03-08T15:05:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![petit223](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@petit223](https://discourse.slicer.org/u/petit223)\
**Post date:** [March 8, 2024, 3:05pm UTC](https://discourse.slicer.org/t/python-code-controls-the-display-of-a-certain-layer-of-slices-in-the-view/34781/1 "2024-03-08T15:05:01Z")

</div>

In the development of the 3D Slicer plug-in, I want to automatically display the corresponding slice on the Green view based on the serial number of the magnetic resonance image entered by the user (I don’t care about the images on the Red and Yellow views)  
For example, I want to use python code to display the 0th magnetic resonance image in the view (I don’t know if this is the right description: coordinates\_ijk[2]=0),

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/b/3bbae0c055b79f61cda6a1bec603159f681a4edb.png)

I already know

```auto
i2rasMatrix = vtk.vtkMatrix4x4()
volumeNode.GetIJKToRASMatrix(i2rasMatrix)
origin = volumeNode.GetOrigin()
spacing = volumeNode.GetSpacing()

```

and I can use

```auto
greenSliceNode = slicer.mrmlScene.GetNodeByID("vtkMRMLSliceNodeGreen")
greenSliceNode.SetSliceOffset(rasCoordinates[2])

```

to control the position under Green view  
However, executing the SetSliceOffset function requires knowing the value of AR (AR: 38.1683mm in the picture) (Is this reasoning correct?)  
The obstacle I encountered was that I could not convert the number of magnetic resonance images and the value of AR.  
Just knowing the value of AR for image 0 is completely enough for me  
Thx!!!
