Slicer Local Threshold Scripted Effect Error

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

1 Like

Did you call segmentEditorNode.SetSelectedSegmentID()?

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

1 Like

@Sunderlandkyl

Thank you so much!

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

The print statements are just for cross referencing purposes

I’ve fixed the bug that was causing the error message in this commit.

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.

1 Like

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

You have two different segment editor widgets in your code.

You create one and assign the segmentation here:

And then you get the widget from the module here:

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

Thank you @Sunderlandkyl

One last question…

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

Thank you!

1 Like

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

slicer.util.selectModule(‘SegmentEditor’)

1 Like