# Transform Widget

**URL:** <https://discourse.slicer.org/t/transform-widget/18274>\
**Category:** Support\
**Tags:** python\
**Created:** [June 22, 2021, 5:46pm UTC](https://discourse.slicer.org/t/transform-widget/18274 "2021-06-22T17:46:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Loc\_Tran](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/loc_tran/32/11116_2.png) [@Loc\_Tran](https://discourse.slicer.org/u/Loc_Tran)\
**Post date:** [June 22, 2021, 5:46pm UTC](https://discourse.slicer.org/t/transform-widget/18274/1 "2021-06-22T17:46:57Z")

</div>

Hello.

I would like to display transformation fields and manipulate some visualization features of the fields such as spacing, scale factor. I tried writing a program to do that based on [this document](https://apidocs.slicer.org/master/classqMRMLTransformDisplayNodeWidget.html#a17c6de69a1f76958684f6b90e94e22bd) but it does not work.

Below is my code:  
#get a field node  
field = getNode(“Transform\_field”)

# get the transforms widget

displacement\_widget = slicer.qMRMLTransformDisplayNodeWidget()  
displacement\_widget.setMRMLTransformNode(field)  
displacement\_widget.setVisibility(True)  
displacement\_widget.setVisibility2d(True)  
#set spacing and scale factors  
displacement\_widget.setGlyphSpacingMm(3)  
displacement\_widget.setGlyphScalePercent(250)

I realized that when I check and uncheck the “visible” or “visible in slice view” checkbox inside visualization section, my program works. It would be great if you could correct my code.

Thank you.

---

<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:** [June 25, 2021, 8:31pm UTC](https://discourse.slicer.org/t/transform-widget/18274/2 "2021-06-25T20:31:57Z")

</div>

You created a GUI widget that you can use to edit properties of a transform display node. The widget is useful if you want to allow users to modify transform display properties in your module’s GUI. It probably does not work if you don’t set the MRML scene in the widget and/or the widget is not displayed.

If you just want to modify a transform’s appearance then you can edit the [transform display node](https://apidocs.slicer.org/master/classvtkMRMLTransformDisplayNode.html) properties directly:

```python
transformNode = getNode('LinearTransform_3')
transformNode.CreateDefaultDisplayNodes()
transformDisplayNode = transformNode.GetDisplayNode()
transformDisplayNode.SetVisibility(True)
transformDisplayNode.SetVisibility2D(True)
transformDisplayNode.SetAndObserveRegionNode(getNode('MRHead'))

```

---

<div class="post-metadata">

**Author:** ![Loc\_Tran](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/loc_tran/32/11116_2.png) [@Loc\_Tran](https://discourse.slicer.org/u/Loc_Tran)\
**Post date:** [June 28, 2021, 8:26pm UTC](https://discourse.slicer.org/t/transform-widget/18274/3 "2021-06-28T20:26:08Z")

</div>

Thank you so much! It works perfectly
