# Python example code for splineWidget.GetSummedLength

**URL:** https://discourse.vtk.org/t/python-example-code-for-splinewidget-getsummedlength/7529
**Category:** Support
**Created:** [December 30, 2021, 1:01pm UTC](https://discourse.vtk.org/t/python-example-code-for-splinewidget-getsummedlength/7529 "2021-12-30T13:01:04Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Dgg820502](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/d/bbce88/32.png) [@Dgg820502](https://discourse.vtk.org/u/Dgg820502)
#### Post date: [December 30, 2021, 1:01pm UTC](https://discourse.vtk.org/t/python-example-code-for-splinewidget-getsummedlength/7529/1 "2021-12-30T13:01:04Z")

</div>

I am trying use splineWidget.GetSummedLength() to get the length of spline, but I always get the same length data no matter how I moved spline around.

Please let know if there is example code for splineWidget.GetSummedLength?

Many thanks in advance.

David.

The following is the code:  
######################################################  
splineWidget =vtk.vtkSplineWidget()  
splineWidget.SetInteractor(iren)  
splineWidget.AddObserver(“EndInteractionEvent”, my\_call\_back)  
##############################################  
iren.Initialize()  
renWin.Render()  
distanceWidget.On()  
angleWidget.On()  
bidimensionalWidget.On()  
splineWidget.On()  
# Initialize the event loop and then start it.  
iren.Start()

def my\_call\_back(pWidget,ev):

```
if (pWidget):
    print(pWidget.GetClassName(), "Event Id:", ev)
    if(ev == "EndInteractionEvent"):
        splineWidget = vtk.vtkSplineWidget()
        splineWidget.SetResolution(10)
        length = splineWidget.GetSummedLength()
        print("spline length = "+str(length))
    ####################################  

```

show(‘C:/results/interpolcontour/s.mhd’)

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [December 31, 2021, 6:17am UTC](https://discourse.vtk.org/t/python-example-code-for-splinewidget-getsummedlength/7529/2 "2021-12-31T06:17:06Z")

</div>

It looks like you are creating a new vtkSplineWidget every time it’s called that’s why the length is the same.

I have just written an example [SplineWidget](https://kitware.github.io/vtk-examples/site/Python/Widgets/SplineWidget/) that shows you how to implement a callback. I’ll probably improve it and write a C++ example in the next few days.

Have a look at the example.

---

<div class="post-metadata">

### Author: ![Dgg820502](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/d/bbce88/32.png) [@Dgg820502](https://discourse.vtk.org/u/Dgg820502)
#### Post date: [December 31, 2021, 9:31am UTC](https://discourse.vtk.org/t/python-example-code-for-splinewidget-getsummedlength/7529/3 "2021-12-31T09:31:59Z")

</div>

Dear Andrew,

Very appreciate for your generous help.

I am implementing your code into mine.

I will let you know any outcomes.

David.

---

<div class="post-metadata">

### Author: ![Dgg820502](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/d/bbce88/32.png) [@Dgg820502](https://discourse.vtk.org/u/Dgg820502)
#### Post date: [December 31, 2021, 9:52am UTC](https://discourse.vtk.org/t/python-example-code-for-splinewidget-getsummedlength/7529/4 "2021-12-31T09:52:10Z")

</div>

Dear Andrew,

Your code is working perfectly.

I can get updated spline length.

Many thanks.

David.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [December 31, 2021, 10:12am UTC](https://discourse.vtk.org/t/python-example-code-for-splinewidget-getsummedlength/7529/5 "2021-12-31T10:12:46Z")

</div>

Happy New Year

Andrew Maclean

---

<div class="post-metadata">

### Author: ![Dgg820502](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/d/bbce88/32.png) [@Dgg820502](https://discourse.vtk.org/u/Dgg820502)
#### Post date: [December 31, 2021, 11:54am UTC](https://discourse.vtk.org/t/python-example-code-for-splinewidget-getsummedlength/7529/6 "2021-12-31T11:54:03Z")

</div>

The same wishes for you in New year.

Be safe and happy.

David
