Cropped volume is not accessible

Operating system:windows 10 ,64bit
Slicer version:4.1120200930
Expected behavior: able to load and do other operations with cropped volume .
Actual behavior: I want to run python script to load an dicom series, get roi and do thresholding inside the roi. For that purpose, I tried to crop the roi using this code :

def createCroppedVolume(inputVolume, roi):


** cropVolumeLogic = slicer.modules.cropvolume.logic()**
** cropVolumeParameterNode = slicer.vtkMRMLCropVolumeParametersNode()**
** cropVolumeParameterNode.SetROINodeID(roi.GetID())**


** cropVolumeParameterNode.SetInputVolumeNodeID(inputVolume.GetID())**
** cropVolumeParameterNode.SetVoxelBased(True)**
** cropVolumeLogic.Apply(cropVolumeParameterNode)**
** cropV = slicer.mrmlScene.GetNodeByID(cropVolumeParameterNode.GetOutputVolumeNodeID())**
** slicer.mrmlScene.AddNode(cropV)**
** return cropV**

after this step, the cropV is not visible on the red or any other slices. but I can see this in the data module as :

image
once i click the data, it becomes visible and again if the cropV is given as input to thresholding function, there is an error saying “crop V is not defined”. kindly help me in this regard. Thanks in advance.

This should be the missing step :

def showInSliceViews(inputVolume)
    views = slicer.app.layoutManager().sliceViewNames()
    for view in views:
        view_logic = slicer.app.layoutManager().sliceWidget(view).sliceLogic()
        view_cn = view_logic.GetSliceCompositeNode()
        view_cn.SetBackgroundVolumeID(inputVolume.GetID())
        view_logic.FitSliceToAll()