# Overwrite existing segments when copying a new segment

**URL:** <https://discourse.slicer.org/t/overwrite-existing-segments-when-copying-a-new-segment/33961>\
**Category:** Support\
**Created:** [January 25, 2024, 5:16am UTC](https://discourse.slicer.org/t/overwrite-existing-segments-when-copying-a-new-segment/33961 "2024-01-25T05:16:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rphellan2210](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rphellan2210/32/79570_2.png) [@rphellan2210](https://discourse.slicer.org/u/rphellan2210)\
**Post date:** [January 25, 2024, 5:16am UTC](https://discourse.slicer.org/t/overwrite-existing-segments-when-copying-a-new-segment/33961/1 "2024-01-25T05:16:02Z")

</div>

Hello,

I have a vtkSegmentation with vtkSegments. When I use the method CopySegmentFromSegmentation(segmentation, segmentId), the corresponding vtkSegment is copied and overlaps the existing vtkSegments in the original vtkSegmentation.

Is there a way to overwrite the existing vtkSegments when copying a new vtkSegment, instead of overlapping?

Renzo

---

<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:** [January 25, 2024, 2:54pm UTC](https://discourse.slicer.org/t/overwrite-existing-segments-when-copying-a-new-segment/33961/2 "2024-01-25T14:54:15Z")

</div>

Copying is different operation than painting. It will not affect any existing segments. If you want to make all segments overwrite the segments before them in the segment list, you can flatten the segmentation into a single layer. If you want to keep overlapping segments and just make some segments overwrite others then you can use the “Logical operators” effect.

---

<div class="post-metadata">

**Author:** ![rphellan2210](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rphellan2210/32/79570_2.png) [@rphellan2210](https://discourse.slicer.org/u/rphellan2210)\
**Post date:** [January 26, 2024, 2:23am UTC](https://discourse.slicer.org/t/overwrite-existing-segments-when-copying-a-new-segment/33961/3 "2024-01-26T02:23:07Z")

</div>

Thank you, Andras. I decided to copy the vtkSegment and then subtract it from all other already existing vtkSegments.
