# How to automatically convert a labelmap volume to a segmentation node upon loading labelmap volume

**URL:** <https://discourse.slicer.org/t/how-to-automatically-convert-a-labelmap-volume-to-a-segmentation-node-upon-loading-labelmap-volume/9931>\
**Category:** Development\
**Created:** [January 23, 2020, 10:43pm UTC](https://discourse.slicer.org/t/how-to-automatically-convert-a-labelmap-volume-to-a-segmentation-node-upon-loading-labelmap-volume/9931 "2020-01-23T22:43:11Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Vincent\_C](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/vincent_c/32/5759_2.png) [@Vincent\_C](https://discourse.slicer.org/u/Vincent_C)\
**Post date:** [January 25, 2020, 1:34am UTC](https://discourse.slicer.org/t/how-to-automatically-convert-a-labelmap-volume-to-a-segmentation-node-upon-loading-labelmap-volume/9931/8 "2020-01-25T01:34:35Z")

</div>

Hi,

So, the script below only allows me to convert a labelmap volume that has already been added to the scene. Is there a way to modify the script so that it applies to all LabelMap volumes I load even if they have not been added to the scene?

labelmapVolumeNode = getNode(‘my\_labelmap\_name’)  
seg = slicer.mrmlScene.AddNewNodeByClass(‘vtkMRMLSegmentationNode’)  
slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(labelmapVolumeNode, seg)

---

_[View the full topic](https://discourse.slicer.org/t/how-to-automatically-convert-a-labelmap-volume-to-a-segmentation-node-upon-loading-labelmap-volume/9931)._
