# How to display a line with interaction handles by python?

**URL:** <https://discourse.slicer.org/t/how-to-display-a-line-with-interaction-handles-by-python/19282>\
**Category:** Support\
**Tags:** python\
**Created:** [August 20, 2021, 1:46pm UTC](https://discourse.slicer.org/t/how-to-display-a-line-with-interaction-handles-by-python/19282 "2021-08-20T13:46:45Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [August 20, 2021, 1:46pm UTC](https://discourse.slicer.org/t/how-to-display-a-line-with-interaction-handles-by-python/19282/1 "2021-08-20T13:46:45Z")

</div>

How to display a line (vtkMRMLMarkupsLineNode) with interaction handles by python?

@lassoan@Juicy@jamesobutler @jcfr @pieper

like that:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/e/deb177e7dc979c19c68bcfd577a3e65e510e3cf7.jpeg)

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [August 20, 2021, 3:21pm UTC](https://discourse.slicer.org/t/how-to-display-a-line-with-interaction-handles-by-python/19282/2 "2021-08-20T15:21:09Z")

</div>

1. First get the reference to vtkMRMLMarkupsLineNode (see [get-mrml-node-from-the-scene](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#get-mrml-node-from-the-scene))
2. Get the DisplayNode for that Line Node. (similar to [change-markup-fiducial-display-properties](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#change-markup-fiducial-display-properties))
3. The interactive handles can be set from the DisplayNode. `SetHandlesInteractive`.

> <https://github.com/Slicer/Slicer/blob/0094e9a35bd266cc8b0e677858dabce797c9928f/Modules/Loadable/Markups/Widgets/qMRMLMarkupsDisplayNodeWidget.cxx#L666>

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [August 20, 2021, 3:34pm UTC](https://discourse.slicer.org/t/how-to-display-a-line-with-interaction-handles-by-python/19282/3 "2021-08-20T15:34:11Z")

</div>

> [@jamesobutler](#):
>
> The interactive handles can be set from the DisplayNode. `SetHandlesInteractive` .

Great! Thanks!  
DisplayNode.SetHandlesInteractive(True)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/8/f84cf43b5b21489cbac1f55af66591f46468bd81.jpeg)

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [August 20, 2021, 3:54pm UTC](https://discourse.slicer.org/t/how-to-display-a-line-with-interaction-handles-by-python/19282/4 "2021-08-20T15:54:10Z")

</div>

@jamesobutler

Is it possible to further control the position of the “origin” and “rotation” or “translate” of the handle?  
是否可以进一步控制handle的"原点"的位置以及"rotation"或者"translate"呢?

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [August 20, 2021, 4:00pm UTC](https://discourse.slicer.org/t/how-to-display-a-line-with-interaction-handles-by-python/19282/5 "2021-08-20T16:00:06Z")

</div>

Yes. They are all methods in the Markups Display Node class.

> <https://github.com/Slicer/Slicer/blob/39be4408f084b3e5d632b373a4985cd7fa6c661b/Modules/Loadable/Markups/MRML/vtkMRMLMarkupsDisplayNode.cxx#L1044-L1061>

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [August 20, 2021, 4:07pm UTC](https://discourse.slicer.org/t/how-to-display-a-line-with-interaction-handles-by-python/19282/6 "2021-08-20T16:07:25Z")

</div>

@jamesobutler

I want the “Origin” of this Handle to be at the end of the line segment instead of the midpoint, how to do it?

我想让这个Handle的原点,在线段的一端而不是中点,怎么做呢?

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [August 20, 2021, 4:24pm UTC](https://discourse.slicer.org/t/how-to-display-a-line-with-interaction-handles-by-python/19282/7 "2021-08-20T16:24:49Z")

</div>

That’s not something that I believe is possible at the moment.

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [August 20, 2021, 4:44pm UTC](https://discourse.slicer.org/t/how-to-display-a-line-with-interaction-handles-by-python/19282/8 "2021-08-20T16:44:01Z")

</div>

@jamesobutler  
Thanks

---

<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:** [August 20, 2021, 6:01pm UTC](https://discourse.slicer.org/t/how-to-display-a-line-with-interaction-handles-by-python/19282/9 "2021-08-20T18:01:29Z")

</div>

You can position a line shaped actor (e.g., that you generated using SlicerIGT extension’s Create Models module) using a transform. You can update the transform from a markups plane node by a few lines of Python code. This technique is used in the [Bone Reconstruction Planner extension](https://github.com/SlicerIGT/SlicerBoneReconstructionPlanner).

---

<div class="post-metadata">

**Author:** ![seanchoi0519](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/seanchoi0519/32/10354_2.png) [@seanchoi0519](https://discourse.slicer.org/u/seanchoi0519)\
**Post date:** [August 21, 2022, 10:07am UTC](https://discourse.slicer.org/t/how-to-display-a-line-with-interaction-handles-by-python/19282/11 "2022-08-21T10:07:08Z")

</div>

Hello, I am trying to find a way to grab 2 planes (generated from markups module) and lock (?) combine them together so when I transform them in position, they move in harmony.

How can I do this **programmatically?** assuming I have displayNodes of both planes.  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![seanchoi0519](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/seanchoi0519/32/10354_2.png) [@seanchoi0519](https://discourse.slicer.org/u/seanchoi0519)\
**Post date:** [August 21, 2022, 1:59pm UTC](https://discourse.slicer.org/t/how-to-display-a-line-with-interaction-handles-by-python/19282/12 "2022-08-21T13:59:26Z")

</div>

Also would there be a way to adjust the size of the interactive handles programmatically?  
Thank you & sorry for many questions

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [August 21, 2022, 2:47pm UTC](https://discourse.slicer.org/t/how-to-display-a-line-with-interaction-handles-by-python/19282/13 "2022-08-21T14:47:03Z")

</div>

没太看懂你的问题, 不过可以看看这个👇或许对你有帮助

> I don’t understand your question very well, but you can take a look at this👇 maybe it will help you…  
> [How to rotate OrthogonalSlicesDeg in slices?](https://discourse.slicer.org/t/how-to-rotate-orthogonalslicesdeg-in-slices/20892/2), [getPlaneIntersectionPoint](https://github.com/SlicerHeart/SlicerHeart/blob/5be64b4b68fcbfbdc7ed463913f52a74208b6d07/ValveView/ValveView.py#L213-L273)

---

<div class="post-metadata">

**Author:** ![seanchoi0519](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/seanchoi0519/32/10354_2.png) [@seanchoi0519](https://discourse.slicer.org/u/seanchoi0519)\
**Post date:** [August 21, 2022, 2:52pm UTC](https://discourse.slicer.org/t/how-to-display-a-line-with-interaction-handles-by-python/19282/15 "2022-08-21T14:52:47Z")

</div>

Thank you, but I do not think it is similar to my problem.  
My problem is:

- I have 2 plane nodes. I want the relationship between the 2 planes to be fixed. If I move 1 of them, I want the other to move by the same amount, if I rotate 1 of them, I want the other to rotate by the same amount

---

<div class="post-metadata">

**Author:** ![seanchoi0519](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/seanchoi0519/32/10354_2.png) [@seanchoi0519](https://discourse.slicer.org/u/seanchoi0519)\
**Post date:** [August 21, 2022, 2:58pm UTC](https://discourse.slicer.org/t/how-to-display-a-line-with-interaction-handles-by-python/19282/16 "2022-08-21T14:58:49Z")

</div>

![Screen Shot 2022-08-22 at 12.57.55 AM](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/d/1de698f9d1a8bd030c56b41e95041ee2f5ee2692.png)

There appears to be a way to do it on the user interface under “Markups module” then “Interactive handles.” How can I do this programmatically?
