# 3D views synchronized using python

**URL:** <https://discourse.slicer.org/t/3d-views-synchronized-using-python/45423>\
**Category:** Development\
**Tags:** python\
**Created:** [December 9, 2025, 3:49pm UTC](https://discourse.slicer.org/t/3d-views-synchronized-using-python/45423 "2025-12-09T15:49:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PimBeentjes](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pimbeentjes/32/81606_2.png) [@PimBeentjes](https://discourse.slicer.org/u/PimBeentjes)\
**Post date:** [December 9, 2025, 3:49pm UTC](https://discourse.slicer.org/t/3d-views-synchronized-using-python/45423/1 "2025-12-09T15:49:56Z")

</div>

I am doing an VR/AR project in 3Dslicer, we open multiple 3D views, for example the black views shown in the image. We also have the blue 3D. We can now synchronize them in slicer by pressing the two interlooped circles, but I was wondering if there is a python function in the slicer library or somewhere else, to automatically synchronize and desynchronize them. I could not find anything on previously posted topics.

Pim

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/b/fbc0adacf9f668524da6148c2c716c471b4d8db1.png)

---

<div class="post-metadata">

**Author:** ![rfenioux](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rfenioux/32/70007_2.png) [@rfenioux](https://discourse.slicer.org/u/rfenioux)\
**Post date:** [December 15, 2025, 10:35am UTC](https://discourse.slicer.org/t/3d-views-synchronized-using-python/45423/2 "2025-12-15T10:35:06Z")

</div>

That would be the `setSliceLink(bool)` function of the slice controller.

You can have a look at [this example](https://github.com/Slicer/Slicer/blob/6b52fb4f787d2eadee9870a3443b199168a0874c/Applications/SlicerApp/Testing/Python/RSNAQuantTutorial.py#L199) to see how to use it (and how to retrieve the slice controller).  
Your views need to be in the same viewgroup, but if it works for you with the button it should already be the case.

---

<div class="post-metadata">

**Author:** ![PimBeentjes](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pimbeentjes/32/81606_2.png) [@PimBeentjes](https://discourse.slicer.org/u/PimBeentjes)\
**Post date:** [December 15, 2025, 10:56am UTC](https://discourse.slicer.org/t/3d-views-synchronized-using-python/45423/3 "2025-12-15T10:56:41Z")

</div>

Thanks for your response. As far as I know this only works for slice views in slicer. But the views I am using are 3d views and indeed that is also what I see when I try to use this. It gives an error that there is no slice with the corresponding name.

Do you know how it works for 3d views?

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [December 15, 2025, 11:05am UTC](https://discourse.slicer.org/t/3d-views-synchronized-using-python/45423/4 "2025-12-15T11:05:50Z")

</div>

For 3D views a different function is used (`SetLinkedControl`), see how it is in the source code when you press the button you mentioned:

> <https://github.com/Slicer/Slicer/blob/6b52fb4f787d2eadee9870a3443b199168a0874c/Libs/MRML/Widgets/qMRMLThreeDViewControllerWidget.cxx#L454>

---

<div class="post-metadata">

**Author:** ![PimBeentjes](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pimbeentjes/32/81606_2.png) [@PimBeentjes](https://discourse.slicer.org/u/PimBeentjes)\
**Post date:** [December 15, 2025, 12:35pm UTC](https://discourse.slicer.org/t/3d-views-synchronized-using-python/45423/5 "2025-12-15T12:35:49Z")

</div>

Yes thanks! This function works great I used it like this:

```
def link3dViews(self):
    lm = slicer.app.layoutManager()
    for name in ["View1", "LeftView", "RightView"]:
        widget = lm.threeDWidget(name)
        if widget and widget.mrmlViewNode():
            widget.mrmlViewNode().SetLinkedControl(True)

def unlink3dViews(self):
    lm = slicer.app.layoutManager()
    for name in ["View1", "LeftView", "RightView"]:
        widget = lm.threeDWidget(name)
        if widget and widget.mrmlViewNode():
            widget.mrmlViewNode().SetLinkedControl(False)

```

Only small bug that is happening, both methods are linked to a separate button, but I have to press unlink twice before the view actually unlinks, any idea why?

---

<div class="post-metadata">

**Author:** ![PimBeentjes](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pimbeentjes/32/81606_2.png) [@PimBeentjes](https://discourse.slicer.org/u/PimBeentjes)\
**Post date:** [December 15, 2025, 1:46pm UTC](https://discourse.slicer.org/t/3d-views-synchronized-using-python/45423/6 "2025-12-15T13:46:01Z")

</div>

Accidently called both functions when trying to only call unlink, so it had to be done twice. This code should work for synchronizing 3d views!
