# How to set ROI of volume in python?

**URL:** <https://discourse.slicer.org/t/how-to-set-roi-of-volume-in-python/13787>\
**Category:** Support\
**Created:** [October 1, 2020, 7:26am UTC](https://discourse.slicer.org/t/how-to-set-roi-of-volume-in-python/13787 "2020-10-01T07:26:41Z")\
**Posts on this page:** 4\
**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, 7:26am UTC](https://discourse.slicer.org/t/how-to-set-roi-of-volume-in-python/13787/1 "2020-10-01T07:26:41Z")

</div>

How can I set cropping ROi mode for a volume in python script?

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [October 1, 2020, 7:33am UTC](https://discourse.slicer.org/t/how-to-set-roi-of-volume-in-python/13787/2 "2020-10-01T07:33:35Z")

</div>

If this is for volume rendering then something like this should work:

```auto
    volRenLogic = slicer.modules.volumerendering.logic()
    displayNode = volRenLogic.GetFirstVolumeRenderingDisplayNode(volumeNode)
    roiNode = displayNode.GetROINode()
    numberOfDisplayNodes = roiNode.GetNumberOfDisplayNodes()
    for i in range(numberOfDisplayNodes):
      roiNode.GetNthDisplayNode(i).SetVisibility(visible)

```

---

<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, 7:55am UTC](https://discourse.slicer.org/t/how-to-set-roi-of-volume-in-python/13787/3 "2020-10-01T07:55:20Z")

</div>

That helped a lot ,thank you. I don’t want to show it in the red slice view.  
How can I do that?  
And also how can I crop to selected ROI in python script?

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [October 1, 2020, 9:04am UTC](https://discourse.slicer.org/t/how-to-set-roi-of-volume-in-python/13787/4 "2020-10-01T09:04:26Z")

</div>

If you have a question that does not fit under the title of the topic then please create a new topic. Thanks
