# Automate "Rotate slice to volume plane" feature in Python

**URL:** https://discourse.slicer.org/t/automate-rotate-slice-to-volume-plane-feature-in-python/3451
**Category:** Development
**Tags:** transforms, python
**Created:** [July 10, 2018, 6:21pm UTC](https://discourse.slicer.org/t/automate-rotate-slice-to-volume-plane-feature-in-python/3451 "2018-07-10T18:21:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![cphillips](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@cphillips](https://discourse.slicer.org/u/cphillips)
#### Post date: [July 10, 2018, 6:21pm UTC](https://discourse.slicer.org/t/automate-rotate-slice-to-volume-plane-feature-in-python/3451/1 "2018-07-10T18:21:11Z")

</div>

Is there anyway to automate rotating a slice window? (I.e. automate the clicking of the “rotate to volume plane” button)

I have tried:

controller = slicer.qMRMLSliceControllerWidget()  
controller.rotateSliceToBackground()

but this doesn’t seem to do anything, and I don’t know how to associate this with a particular slice window (i.e. a particular qMRMLSliceWidget)

---

<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: [July 10, 2018, 8:25pm UTC](https://discourse.slicer.org/t/automate-rotate-slice-to-volume-plane-feature-in-python/3451/2 "2018-07-10T20:25:18Z")

</div>

Examples in the script repository should help: [https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Manipulate\_a\_Slice\_View](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Manipulate_a_Slice_View)

---

<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: [July 11, 2018, 9:49pm UTC](https://discourse.slicer.org/t/automate-rotate-slice-to-volume-plane-feature-in-python/3451/3 "2018-07-11T21:49:32Z")

</div>

> [@cphillips](#):
>
> controller = slicer.qMRMLSliceControllerWidget()  
> controller.rotateSliceToBackground()
> 
> but this doesn’t seem to do anything, and I don’t know how to associate this with a particular slice window (i.e. a particular qMRMLSliceWidget)

That will just create an instance of a new controller widget but you want the ones that are associated with views in the layout, like this from the examples @lassoan linked:

```auto
for sliceViewName in layoutManager.sliceViewNames():
     sliceWidget = layoutManager.sliceWidget(sliceViewName)
     
     controller = sliceWidget.sliceController()

```
