# Centering on a segment from a script

**URL:** https://discourse.slicer.org/t/centering-on-a-segment-from-a-script/6209
**Category:** Development
**Tags:** segmentation
**Created:** [March 19, 2019, 2:34pm UTC](https://discourse.slicer.org/t/centering-on-a-segment-from-a-script/6209 "2019-03-19T14:34:45Z")
**Posts on this page:** 1
**Showing post:** 9

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [March 19, 2019, 9:01pm UTC](https://discourse.slicer.org/t/centering-on-a-segment-from-a-script/6209/9 "2019-03-19T21:01:32Z")

</div>

Using a custom extension is certainly a solution, but in the long term I would recommend developers to use Slicer core functions if available.

Slicer-4.10 returning a swig pointer (such as `_000001bfd4897340_p_void`) is a minor inconvenience. You can still access the values using the helper function below (in the nightly version the VTK hint is there so the position is directly returned as a Python tuple).

```auto
def getListFromPointer(bufferPtr, scalarType=vtk.VTK_DOUBLE, numberOfElements=3):
  """Convert swig pointer (_..._p_void) to list object"""
  bufferArray = vtk.vtkAbstractArray.CreateArray(vtk.VTK_DOUBLE)
  bufferArray.SetVoidArray(bufferPtr, numberOfElements, True)
  buffer = [bufferArray.GetValue(i) for i in range(numberOfElements)]
  return buffer

```

Example usage:

```auto
>>> ptr=getNode('Segmentation').GetSegmentCenter("Segment_1")
>>> ptr
'_000001bfd4897340_p_void'
>>> getListFromPointer(ptr)
[8.254768371581932, -18.07139587402301, -10.214302062987997]

```

---

_[View the full topic](https://discourse.slicer.org/t/centering-on-a-segment-from-a-script/6209)._
