# Orienting views with respect to a selected markup

**URL:** <https://discourse.slicer.org/t/orienting-views-with-respect-to-a-selected-markup/26780>\
**Category:** Support\
**Created:** [December 17, 2022, 12:04am UTC](https://discourse.slicer.org/t/orienting-views-with-respect-to-a-selected-markup/26780 "2022-12-17T00:04:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karl\_Hahn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/karl_hahn/32/15290_2.png) [@Karl\_Hahn](https://discourse.slicer.org/u/Karl_Hahn)\
**Post date:** [December 17, 2022, 12:04am UTC](https://discourse.slicer.org/t/orienting-views-with-respect-to-a-selected-markup/26780/1 "2022-12-17T00:04:59Z")

</div>

Hello,

For sake of reference, are there any particular Slicer modules that implement functionality to orient views with respect to a markup selected in the Markups module? For example, selecting a Plane reformats the views such that one is coplanar with the Plane and the others are mutually orthogonal.

I did notice that basic centering functionality is available, e.g. when clicking a point in a Point List or the origin of a Plane. The use cases of interest here are somewhat beyond this and perhaps more application-specific.

Thanks for the guidance!

Karl

---

<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:** [December 19, 2022, 4:31pm UTC](https://discourse.slicer.org/t/orienting-views-with-respect-to-a-selected-markup/26780/2 "2022-12-19T16:31:23Z")

</div>

You can use `Volume reslice driver` module in SlicerIGT extension to “drive” (position and orient) a slice view by plan eor line markup. You can also use Path Explorer for reslicing along and around markup line nodes.

You can also create any customized behavior using a few lines of Python script (add an observer to a markup node and modify slice position and orientation whenever the markup is changed. You can find examples in the [script repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#markups).

---

<div class="post-metadata">

**Author:** ![Karl\_Hahn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/karl_hahn/32/15290_2.png) [@Karl\_Hahn](https://discourse.slicer.org/u/Karl_Hahn)\
**Post date:** [December 21, 2022, 8:27pm UTC](https://discourse.slicer.org/t/orienting-views-with-respect-to-a-selected-markup/26780/3 "2022-12-21T20:27:11Z")

</div>

Hi @lassoan, a follow-up question: the relevant examples in the script repository observe markup modification, but I would like to trigger view reformatting when a markup is selected. What is the proper way to observe changes in markup selection, specifically in the list shown in the markups module? Do I assume correctly that selection is different from modification?

Thanks!

---

<div class="post-metadata">

**Author:** ![Karl\_Hahn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/karl_hahn/32/15290_2.png) [@Karl\_Hahn](https://discourse.slicer.org/u/Karl_Hahn)\
**Post date:** [December 21, 2022, 10:21pm UTC](https://discourse.slicer.org/t/orienting-views-with-respect-to-a-selected-markup/26780/4 "2022-12-21T22:21:30Z")

</div>

Observing the `vtkMRMLSelectionNode` might accomplish the desired end. Unsure if this is an intended use case, though.

Crudely:

```auto
last_id = None

def reformat_if_selection_changed(active_id):
    if active_id!= last_id:
        ...reformat views...
        last_id = active_id

sn = slicer.app.applicationLogic().GetSelectionNode()
sn.AddObserver(
    slicer.vtkMRMLSelectionNode.ActivePlaceNodeIDChangedEvent, 
    lambda c, e: reformat_if_selection_changed(c.GetActivePlaceNodeID())
)

```
