# Slicer Local Threshold Scripted Effect Error

**URL:** https://discourse.slicer.org/t/slicer-local-threshold-scripted-effect-error/12463
**Category:** Development
**Created:** [July 9, 2020, 4:48pm UTC](https://discourse.slicer.org/t/slicer-local-threshold-scripted-effect-error/12463 "2020-07-09T16:48:09Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![vertebra](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/vertebra/32/7475_2.png) [@vertebra](https://discourse.slicer.org/u/vertebra)
#### Post date: [July 9, 2020, 4:48pm UTC](https://discourse.slicer.org/t/slicer-local-threshold-scripted-effect-error/12463/1 "2020-07-09T16:48:09Z")

</div>

When we run our code in the Python interactor, our code enters an infinite error sequence pointing to line 75 in SegmentEditorEffect.py

This line reads: r,g,b = segmentationNode.GetSegmentation().GetSegment(segmentID).GetColor()

The error says that segmentID is the issue

In our code, we create our segment:

segmentationNode.AddSegmentFromClosedSurfaceRepresentation(lumbarSeed.GetOutput(), “Lumbar-” + str(x+1), [random(), random(), random()], str(x+1))

Do you have any idea for the issue? What do we change to repair this bug? @lassoan @cpinter

---

<div class="post-metadata">

### Author: ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)
#### Post date: [July 9, 2020, 5:11pm UTC](https://discourse.slicer.org/t/slicer-local-threshold-scripted-effect-error/12463/2 "2020-07-09T17:11:45Z")

</div>

Did you call segmentEditorNode.SetSelectedSegmentID()?

If you can upload your code somewhere, I can take a look at the error.

---

<div class="post-metadata">

### Author: ![vertebra](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/vertebra/32/7475_2.png) [@vertebra](https://discourse.slicer.org/u/vertebra)
#### Post date: [July 9, 2020, 5:20pm UTC](https://discourse.slicer.org/t/slicer-local-threshold-scripted-effect-error/12463/3 "2020-07-09T17:20:34Z")

</div>

@Sunderlandkyl

Thank you so much!

This is our code(we also have the local threshold functions, but the link is just the “run” code)

> <https://github.com/kbehlmirusmed/VertebraSeg/blob/master/VertebraSeg.py>

The print statements are just for cross referencing purposes

---

<div class="post-metadata">

### Author: ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)
#### Post date: [July 9, 2020, 6:52pm UTC](https://discourse.slicer.org/t/slicer-local-threshold-scripted-effect-error/12463/4 "2020-07-09T18:52:00Z")

</div>

I’ve fixed the bug that was causing the error message [in this commit](https://github.com/lassoan/SlicerSegmentEditorExtraEffects/commit/584e02c9fcdc62285ff2e2332bd7308a6b7ceeeb).

You should still select the segment that you would like to edit by calling segmentationNode.SetSelectedSegmentID(segmentID) to ensure that the correct segment is modified. This should also have the side effect of preventing the errors.

---

<div class="post-metadata">

### Author: ![vertebra](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/vertebra/32/7475_2.png) [@vertebra](https://discourse.slicer.org/u/vertebra)
#### Post date: [July 9, 2020, 7:32pm UTC](https://discourse.slicer.org/t/slicer-local-threshold-scripted-effect-error/12463/5 "2020-07-09T19:32:14Z")

</div>

Thank you so much Kyle!

One last question: when we run it, for some reason even though we set the segmentationNode, it does not switch to the newly created segmentationNode on Slicer. The segment editor says that we are still in the original Segmentation(always called “Segmentation”). Do you know why it wouldn’t switch to VertebraL1?c @Sunderlandkyl

---

<div class="post-metadata">

### Author: ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)
#### Post date: [July 9, 2020, 8:20pm UTC](https://discourse.slicer.org/t/slicer-local-threshold-scripted-effect-error/12463/6 "2020-07-09T20:20:51Z")

</div>

You have two different segment editor widgets in your code.

You create one and assign the segmentation here:

> <https://github.com/kbehlmirusmed/VertebraSeg/blob/cf64dcfe6ebb8fd40d3b80af394852b6c04d3572/VertebraSeg.py#L34-L40>

And then you get the widget from the module here:

> <https://github.com/kbehlmirusmed/VertebraSeg/blob/cf64dcfe6ebb8fd40d3b80af394852b6c04d3572/VertebraSeg.py#L41-L43>

Probably you need to delete the first one from the code, and only use the widget from the Segment Editor module.

---

<div class="post-metadata">

### Author: ![vertebra](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/vertebra/32/7475_2.png) [@vertebra](https://discourse.slicer.org/u/vertebra)
#### Post date: [July 10, 2020, 12:34pm UTC](https://discourse.slicer.org/t/slicer-local-threshold-scripted-effect-error/12463/7 "2020-07-10T12:34:01Z")

</div>

Thank you @Sunderlandkyl

One last question…

Is there a way to open up the segment editor module from the python interactor?

Thank you!

---

<div class="post-metadata">

### Author: ![vertebrae](https://avatars.discourse-cdn.com/v4/letter/v/dec6dc/32.png) [@vertebrae](https://discourse.slicer.org/u/vertebrae)
#### Post date: [July 10, 2020, 3:32pm UTC](https://discourse.slicer.org/t/slicer-local-threshold-scripted-effect-error/12463/8 "2020-07-10T15:32:17Z")

</div>

Does anyone have a response to this? We looked in some class references and did not find anything that worked. @lassoan

---

<div class="post-metadata">

### Author: ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)
#### Post date: [July 10, 2020, 3:49pm UTC](https://discourse.slicer.org/t/slicer-local-threshold-scripted-effect-error/12463/9 "2020-07-10T15:49:47Z")

</div>

> slicer.util.selectModule(‘SegmentEditor’)
