# How to get current volume and segment in Python

**URL:** https://discourse.slicer.org/t/how-to-get-current-volume-and-segment-in-python/11313
**Category:** Development
**Created:** [April 27, 2020, 11:57am UTC](https://discourse.slicer.org/t/how-to-get-current-volume-and-segment-in-python/11313 "2020-04-27T11:57:26Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Shicong](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shicong/32/6562_2.png) [@Shicong](https://discourse.slicer.org/u/Shicong)
#### Post date: [April 27, 2020, 11:57am UTC](https://discourse.slicer.org/t/how-to-get-current-volume-and-segment-in-python/11313/1 "2020-04-27T11:57:26Z")

</div>

When going to the volumeclipmodel module, as shown in the diagram, you have to manually mouse to select the volume and segment, how to automatically get these two objects in the python code, is there a code interface? thanks!

 ![图片](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/0/40da7b5a9dc2ba22ebea2994250639021e19d18c.jpeg)

---

<div class="post-metadata">

### Author: ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)
#### Post date: [April 27, 2020, 2:29pm UTC](https://discourse.slicer.org/t/how-to-get-current-volume-and-segment-in-python/11313/2 "2020-04-27T14:29:59Z")

</div>

You can get the parameter node for the VolumeClipWithModel module with this code:

```auto
volumeClipWithModelNode = slicer.mrmlScene.GetSingletonNode("VolumeClipWithModel", "vtkMRMLScriptedModuleNode")

```

And get the parameters with this code:

```auto
inputVolume = volumeClipWithModelNode.GetNodeReference("InputVolume")
clippingModel = volumeClipWithModelNode.GetNodeReference("ClippingModel")
outputVolume = volumeClipWithModelNode.GetNodeReference("OutputVolume")

```

What is your workflow?  
If you are doing the segmentation in the segment editor and then exporting the segment to a model to use in volume clip with model, you can perform the masking directly within the segment editor by using the “Mask volume” effect from the “Segment Editor Extra Effects” extension.

---

<div class="post-metadata">

### Author: ![Shicong](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shicong/32/6562_2.png) [@Shicong](https://discourse.slicer.org/u/Shicong)
#### Post date: [April 28, 2020, 2:38am UTC](https://discourse.slicer.org/t/how-to-get-current-volume-and-segment-in-python/11313/3 "2020-04-28T02:38:03Z")

</div>

Thank you,I wish you a happy working life! 😄

---

<div class="post-metadata">

### Author: ![Shicong](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shicong/32/6562_2.png) [@Shicong](https://discourse.slicer.org/u/Shicong)
#### Post date: [April 28, 2020, 4:17am UTC](https://discourse.slicer.org/t/how-to-get-current-volume-and-segment-in-python/11313/4 "2020-04-28T04:17:34Z")

</div>

What’s more, it’s the default not on the volumeclipwithmodel “, the display is “select a volume” and & quot;select a model”, without the mouse select, I want to get the active volume object of the volumes module from the python code, and the current model object of the module. Note that I am going to get volume and model objects in the python code, can you provide the code? Thank you so much! !!!  
 ![图片](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/a/7a2fa87d951ad8d680f5ac843d580206b4c45855.png)

 ![图片](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/4/d46a987061d0f74dc1ad9925dd4befcc70d06c94.png)  
 ![图片](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/1/914416c9071e59484c7f11d88716492b12dea189.png)
