# Cropped volume is not accessible

**URL:** <https://discourse.slicer.org/t/cropped-volume-is-not-accessible/17732>\
**Category:** Support\
**Tags:** python, cropping\
**Created:** [May 22, 2021, 10:21am UTC](https://discourse.slicer.org/t/cropped-volume-is-not-accessible/17732 "2021-05-22T10:21:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![KAVIYA\_DHARSHINI](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/kaviya_dharshini/32/10955_2.png) [@KAVIYA\_DHARSHINI](https://discourse.slicer.org/u/KAVIYA_DHARSHINI)\
**Post date:** [May 22, 2021, 10:21am UTC](https://discourse.slicer.org/t/cropped-volume-is-not-accessible/17732/1 "2021-05-22T10:21:31Z")

</div>

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](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/1/31ede708e9df8f64c7025058ebb40865e1e4caa3.png)  
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.

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [May 23, 2021, 7:02pm UTC](https://discourse.slicer.org/t/cropped-volume-is-not-accessible/17732/2 "2021-05-23T19:02:34Z")

</div>

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()
```
