# Achieve "Click to jump Slices -\> centered" programmatically

**URL:** <https://discourse.slicer.org/t/achieve-click-to-jump-slices-centered-programmatically/12969>\
**Category:** Development\
**Tags:** markups-fiducials\
**Created:** [August 12, 2020, 8:57pm UTC](https://discourse.slicer.org/t/achieve-click-to-jump-slices-centered-programmatically/12969 "2020-08-12T20:57:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mangotee](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@mangotee](https://discourse.slicer.org/u/mangotee)\
**Post date:** [August 12, 2020, 8:57pm UTC](https://discourse.slicer.org/t/achieve-click-to-jump-slices-centered-programmatically/12969/1 "2020-08-12T20:57:49Z")

</div>

Hi all,  
I would like to achieve the fiducial feature “Click to Jump Slices” programmatically. I know how to achieve this for the Red/Green/Yellow _offsets_, but I would like the slice views to get centered on the fiducial location as well. Here’s how I set the offset:

```
lm = slicer.app.layoutManager()
# for a point with coordinates x/y/z (floats in mm)
for slice, loc in zip(['Yellow','Green','Red'], [x,y,z]):
    sliceNode = lm.sliceWidget(slice) # can be Red/Yellow
    sliceLogic = sliceNode.sliceLogic()
    sliceLogic.SetSliceOffset(loc)

```

Unfortunately, I cannot see sth like “SetSliceCenter” in sliceLogic.  
Thx for your help in advance!

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [August 12, 2020, 9:48pm UTC](https://discourse.slicer.org/t/achieve-click-to-jump-slices-centered-programmatically/12969/2 "2020-08-12T21:48:04Z")

</div>

You can search the source code for `vtkMRMLSliceNode::JumpSliceByCentering`

---

<div class="post-metadata">

**Author:** ![mangotee](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@mangotee](https://discourse.slicer.org/u/mangotee)\
**Post date:** [August 13, 2020, 9:32am UTC](https://discourse.slicer.org/t/achieve-click-to-jump-slices-centered-programmatically/12969/3 "2020-08-13T09:32:04Z")

</div>

Thank you Steve, that helped a lot. I realized that the sliceNode that I retrieved above was not a sliceNode at all, but actually a widget of class `qMRMLSliceWidget`. The function `JumpSliceByCentering` is a method of class `vtkMRMLSliceNode` though. If somebody else stumbles across this, the code above should be modified. It should _not_ make the slice jump through the widget’s `sliceLogic`, instead it should read:

```
lm = slicer.app.layoutManager()
# for a point with coordinates x/y/z (floats in mm)
# (better denoted as r/a/s, as in Slicer source code)
for slice in ['Yellow','Green','Red']:
    sliceNode = lm.sliceWidget(slice).mrmlSliceNode()
    sliceNode.JumpSliceByCentering(x,y,z) # or r,a,s

    # NOTE: in case you only want to offset, not center:
    # sliceNode.JumpSliceByOffsetting(x,y,z) # or r,a,s
```
