# Copy/move segments programmatically in Python in Segmentations module

**URL:** <https://discourse.slicer.org/t/copy-move-segments-programmatically-in-python-in-segmentations-module/20758>\
**Category:** Development\
**Tags:** segmentation, python\
**Created:** [November 23, 2021, 6:15pm UTC](https://discourse.slicer.org/t/copy-move-segments-programmatically-in-python-in-segmentations-module/20758 "2021-11-23T18:15:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nthach17](https://avatars.discourse-cdn.com/v4/letter/n/dec6dc/32.png) [@nthach17](https://discourse.slicer.org/u/nthach17)\
**Post date:** [November 23, 2021, 6:15pm UTC](https://discourse.slicer.org/t/copy-move-segments-programmatically-in-python-in-segmentations-module/20758/1 "2021-11-23T18:15:14Z")

</div>

Slicer version: 4.11.20210226

Hello,

I’m writing a Python script for moving segments from a segmentation node to another. I looked up the source code and found that the function in C++ is `qSlicerSegmentationsModuleWidget::copySegmentBetweenSegmentations()`. However, the equivalent function in Python, i.e. `slicer.modules.segmentations.widgetRepresentation().CopySegmentBetweenSegmentations()` does not exist. Am I missing something?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 23, 2021, 6:39pm UTC](https://discourse.slicer.org/t/copy-move-segments-programmatically-in-python-in-segmentations-module/20758/2 "2021-11-23T18:39:44Z")

</div>

Module widget methods are not to be called from other modules or scripts. You need to [dig one level deeper](https://github.com/Slicer/Slicer/blob/56ebd8ee84557fe0c67e9db8fe0ddd771d799751/Modules/Loadable/Segmentations/qSlicerSegmentationsModuleWidget.cxx#L799) and call [vtkSegmentation::CopySegmentFromSegmentation method](http://apidocs.slicer.org/master/classvtkSegmentation.html#a001c13d90bea679cb7697e33e56b59e5) from Python.

---

<div class="post-metadata">

**Author:** ![nthach17](https://avatars.discourse-cdn.com/v4/letter/n/dec6dc/32.png) [@nthach17](https://discourse.slicer.org/u/nthach17)\
**Post date:** [November 23, 2021, 6:58pm UTC](https://discourse.slicer.org/t/copy-move-segments-programmatically-in-python-in-segmentations-module/20758/3 "2021-11-23T18:58:17Z")

</div>

It works now! Thank you for the quick response!
