# Link slice views outside of slicerrc.py

**URL:** https://discourse.slicer.org/t/link-slice-views-outside-of-slicerrc-py/20913
**Category:** Support
**Tags:** views
**Created:** [December 5, 2021, 7:35am UTC](https://discourse.slicer.org/t/link-slice-views-outside-of-slicerrc-py/20913 "2021-12-05T07:35:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![koeglfryderyk](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/koeglfryderyk/32/14638_2.png) [@koeglfryderyk](https://discourse.slicer.org/u/koeglfryderyk)
#### Post date: [December 5, 2021, 7:35am UTC](https://discourse.slicer.org/t/link-slice-views-outside-of-slicerrc-py/20913/1 "2021-12-05T07:35:58Z")

</div>

I’m writing an extension and I would like that it automatically links the slice views. I know I can add it to .slicerrc.py, and this works, however, I wouldn’t want to ‘ship’ a custom .slicerrc.py together with my extension.

I tried to take the code from [Set all slice views linked by default](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#set-all-slice-views-linked-by-default), put it in a function `linkViews()` in my MyExtension.py and add it to the the ` __init__ ()` of `class MyExtension(ScriptedLoadableModule)` similarily to the sample data:  
`slicer.app.connect("startupCompleted()", linkViews)`

However, this doesn’t work - it doesn’t throw any error - the code gets executed (if I add a print() it prints to the console) but the views remain unlinked.

Can this be done as part of an extension?

---

<div class="post-metadata">

### Author: ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)
#### Post date: [December 5, 2021, 5:19pm UTC](https://discourse.slicer.org/t/link-slice-views-outside-of-slicerrc-py/20913/2 "2021-12-05T17:19:02Z")

</div>

This is probably a timing issue - the `startupCompleted` signal comes after the windows already exist, while the `slicerrc.py` is processed during command line processing where the windows must not have been set up yet.

Can you try calling `linkViews` directly in the ` __init__ ()`?

> <https://github.com/Slicer/Slicer/blob/4960b400b3d7135a7b03f28a408358a650fc0a82/Base/QTApp/qSlicerApplicationHelper.txx#L221-L241>

---

<div class="post-metadata">

### Author: ![koeglfryderyk](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/koeglfryderyk/32/14638_2.png) [@koeglfryderyk](https://discourse.slicer.org/u/koeglfryderyk)
#### Post date: [December 6, 2021, 4:13pm UTC](https://discourse.slicer.org/t/link-slice-views-outside-of-slicerrc-py/20913/3 "2021-12-06T16:13:27Z")

</div>

Calling `linkViews` directly in the ` __init__ ()` of `MyExtension(ScriptedLoadableModule)` doesn’t work.

However, it works when I call it in the ` __init__ ()` of `MyExtensionWidget(ScriptedLoadableModuleWidget, VTKObservationMixin)` or `MyExtensionLogic(ScriptedLoadableModuleLogic)`
