# Shallow copy a node into a scene

**URL:** <https://discourse.slicer.org/t/shallow-copy-a-node-into-a-scene/20101>\
**Category:** Development\
**Created:** [October 11, 2021, 4:56pm UTC](https://discourse.slicer.org/t/shallow-copy-a-node-into-a-scene/20101 "2021-10-11T16:56:20Z")\
**Posts on this page:** 4\
**Page:** 1

<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:** [October 11, 2021, 4:56pm UTC](https://discourse.slicer.org/t/shallow-copy-a-node-into-a-scene/20101/1 "2021-10-11T16:56:20Z")

</div>

I’ve created a scene and I want to copy nodes from the current scene into my new scene.  
But I don’t want to copy any underlying bulk data in the nodes. I want new nodes that refer to the same underlying data when there is any. Is this possible in the current api with `vtkMRMLScene` or `vtkMRMLNode`?

`vtkMRMLScene::CopyNode` seems to do a deep copy.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [October 11, 2021, 5:19pm UTC](https://discourse.slicer.org/t/shallow-copy-a-node-into-a-scene/20101/2 "2021-10-11T17:19:40Z")

</div>

Looking at the `CopyContent` function should be helpful:

> <https://github.com/Slicer/Slicer/blob/03e913587bf7b78990f0224bc77818e3ed31d5d3/Libs/MRML/Core/vtkMRMLNode.h#L237-L246>

---

<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:** [October 11, 2021, 6:05pm UTC](https://discourse.slicer.org/t/shallow-copy-a-node-into-a-scene/20101/3 "2021-10-11T18:05:25Z")

</div>

I thought this might help, but the `deepCopy` parameter [doesn’t get used](https://github.com/Slicer/Slicer/blob/03e913587bf7b78990f0224bc77818e3ed31d5d3/Libs/MRML/Core/vtkMRMLNode.cxx#L132-L140). And I’m not seeing `CopyContent` get overriden by descendants of `vtkMRMLNode`. Maybe I am missing something-- I will test and see if it really does a shallow copy.

---

<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:** [October 11, 2021, 7:14pm UTC](https://discourse.slicer.org/t/shallow-copy-a-node-into-a-scene/20101/4 "2021-10-11T19:14:57Z")

</div>

I was indeed missing something:  
`CopyContent` does get overriden, the override was just tucked into the macro `vtkMRMLCopyContentMacro`.

Thanks @jcfr, I think this should do what I need!
