@staticmethod
    def getActiveVolumeIdInSlice(sliceName):
        layoutManager = slicer.app.layoutManager()
        compositeNode = layoutManager.sliceWidget(sliceName).mrmlSliceCompositeNode()
        node = compositeNode.GetBackgroundVolumeID()
        if node is not None:
            return node
        # If background is None, try foreground
        node = compositeNode.GetForegroundVolumeID()
        return node
Get the active volume in a 2D Slice (background if possible, foreground otherwise)
dataset/ETHPy150Open acil-bwh/SlicerCIP/Scripted/CIP_Common/CIP/logic/SlicerUtil.py/SlicerUtil.getActiveVolumeIdInSlice