# Can I move segments from one segmentation to another segmentation using a Script?

**URL:** <https://discourse.slicer.org/t/can-i-move-segments-from-one-segmentation-to-another-segmentation-using-a-script/31077>\
**Category:** Support\
**Tags:** segmentation, python\
**Created:** [August 9, 2023, 8:54pm UTC](https://discourse.slicer.org/t/can-i-move-segments-from-one-segmentation-to-another-segmentation-using-a-script/31077 "2023-08-09T20:54:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergio](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sergio](https://discourse.slicer.org/u/Sergio)\
**Post date:** [August 9, 2023, 8:54pm UTC](https://discourse.slicer.org/t/can-i-move-segments-from-one-segmentation-to-another-segmentation-using-a-script/31077/1 "2023-08-09T20:54:19Z")

</div>

![Capture](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/5/65c261a2a2b88a235ba3e265ecc16beb0c7e4347.jpeg)

For example, I would like to move the body\_trunc and the body\_extremities to Organs.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![ebrahim](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ebrahim/32/13403_2.png) [@ebrahim](https://discourse.slicer.org/u/ebrahim)\
**Post date:** [August 9, 2023, 11:42pm UTC](https://discourse.slicer.org/t/can-i-move-segments-from-one-segmentation-to-another-segmentation-using-a-script/31077/2 "2023-08-09T23:42:05Z")

</div>

I think this would work

```py
source_segmentation = getNode('BodyContour').GetSegmentation()
source_segment_id = source_segmentation.GetSegmentIdBySegmentName('body_trunc') # repeat for each segment we want to move
target_segmentation = getNode('Organs').GetSegmentation()
target_segmentation.CopySegmentFromSegmentation(source_segmentation, source_segment_id, True)

```

(the last parameter `True` is `removeFromSource` [here](https://apidocs.slicer.org/master/classvtkSegmentation.html#a001c13d90bea679cb7697e33e56b59e5))  
(I don’t know if there is a data copy going on or if there is a way to avoid it)
