# Display specific slices

**URL:** <https://discourse.slicer.org/t/display-specific-slices/2132>\
**Category:** Development\
**Created:** [February 20, 2018, 8:56pm UTC](https://discourse.slicer.org/t/display-specific-slices/2132 "2018-02-20T20:56:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [February 20, 2018, 8:56pm UTC](https://discourse.slicer.org/t/display-specific-slices/2132/1 "2018-02-20T20:56:56Z")

</div>

Dear all,

I am trying to display a specific location (providing the world coordinates in self.CPos )I tried this code but I keep getting slicer default:

```
    # The volumes are added to the Red (axial) slice of the scene.
    red_logic = slicer.app.layoutManager().sliceWidget("Red").sliceLogic()
    red_cn = red_logic.GetSliceCompositeNode()
    red_cn.SetBackgroundVolumeID(inputNode.GetID())
    red_cn.SetLabelVolumeID(resultNode.GetID())
    red_logic.SetSliceOffset(self.CPos[2])

    # The volumes are added to the Yellow (sagittal) slice of the scene.
    yellow_logic = slicer.app.layoutManager().sliceWidget("Yellow").sliceLogic()
    yellow_cn = yellow_logic.GetSliceCompositeNode()
    yellow_cn.SetBackgroundVolumeID(inputNode.GetID())
    yellow_cn.SetLabelVolumeID(resultNode.GetID())
    yellow_logic.SetSliceOffset(self.CPos[1])

    # The volumes are added to the Green (coronal) slice of the scene.
    green_logic = slicer.app.layoutManager().sliceWidget("Green").sliceLogic()
    green_cn = green_logic.GetSliceCompositeNode()
    green_cn.SetBackgroundVolumeID(inputNode.GetID())
    green_cn.SetLabelVolumeID(resultNode.GetID())
    green_logic.SetSliceOffset(self.CPos[0])

    # The layout is set to show only the Red slice by default.
    lm = slicer.app.layoutManager()
    lm.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutOneUpRedSliceView)

    # Fit slices to window
    sliceNodes = slicer.util.getNodes('vtkMRMLSliceNode*')
    layoutManager = slicer.app.layoutManager()
    for sliceNode in sliceNodes.values():
        sliceWidget = layoutManager.sliceWidget(sliceNode.GetLayoutName())
        if sliceWidget:
            sliceWidget.sliceLogic().FitSliceToAll() 

```

so if I commented out the lines contains SetSliceOffset or use them I get the same default result. I tried the function in slicer python interactor and it works. I tried replacing the variable self.Cpos with the actual values but nothing change.

Am I missing something?

Thanks  
Ibraheem

---

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [February 21, 2018, 10:32am UTC](https://discourse.slicer.org/t/display-specific-slices/2132/2 "2018-02-21T10:32:29Z")

</div>

I figured out that I loaded some images after this code which remove its effect. The code works now.
