How to call the "Islands" function of the Segment Editor from a python script with "Keep selected island"

Hi,

I am developing an semiautomated script for CT lung masking.
After thresholding and cutting out segments of the trachea and left main bronchus (works), I normally use the “Islands” function of the Segment Editor next with the parameter “Keep selected island”.

However, something like this

    ...
    segmentEditorWidget.setActiveEffectByName("Islands")
    effect = segmentEditorWidget.activeEffect()
    effect.setParameter("Operation","KEEP_SELECTED_ISLAND")
    effect.setParameter("MinimumSize","1000")
    effect.self().onApply()
    ...

does not work from my script.
How can I pass coordinates / selected slice view / mouse click ?
Would be glad if someone had an idea or a code snippet.

Thanks, best regards
rudolf

Found the solution myself.
Enjoy.

Thanks for sharing. You could make your code simpler and more robust by slightly changing the Islands effect so that it can take a 3D coordinate directly (not just an interaction event that you need to simulate via the GUI). The effect is a simple Python script, which you can freely modify locally (you could inject the 3D coordinate here). If the modification works well for you then you can send us a pull request so that we can integrate that change into Slicer core.

@rbumm 我想知道这个代码只是在一个slice上选点,可是这个slice如何确定呢…我想说的是三维空间的第三个点怎么确定呢?

I want to know that this code just selects a point on a slice, but how to determine this slice…What I want to konw is how to determine the third point in the three-dimensional space?

@lassoan 没有更简洁的方法,直接输入the 3D coordinate来获取island?

There is no more concise way that inject the 3D coordinate to get the island…e.g. effiect.setparameter()