# How top crop the volume using python?

**URL:** <https://discourse.slicer.org/t/how-top-crop-the-volume-using-python/13791>\
**Category:** Support\
**Created:** [October 1, 2020, 9:41am UTC](https://discourse.slicer.org/t/how-top-crop-the-volume-using-python/13791 "2020-10-01T09:41:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chintha\_Siva\_Prasad](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chintha_siva_prasad/32/7766_2.png) [@Chintha\_Siva\_Prasad](https://discourse.slicer.org/u/Chintha_Siva_Prasad)\
**Post date:** [October 1, 2020, 9:41am UTC](https://discourse.slicer.org/t/how-top-crop-the-volume-using-python/13791/1 "2020-10-01T09:41:07Z")

</div>

I had selected the ROI of a volume.And want to crop it in python.  
How can I do this?

---

<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:** [October 1, 2020, 10:13am UTC](https://discourse.slicer.org/t/how-top-crop-the-volume-using-python/13791/2 "2020-10-01T10:13:40Z")

</div>

Assuming roi and inputVolume are defined :

```python
cropLogic = slicer.modules.cropvolume.logic()
cvpn = slicer.vtkMRMLCropVolumeParametersNode()

cvpn.SetROINodeID(roi.GetID())
cvpn.SetInputVolumeNodeID(inputVolume.GetID())
cropLogic.Apply(cvpn)

```
