# Apply a nonlinear transform to model using Python code

**URL:** <https://discourse.slicer.org/t/apply-a-nonlinear-transform-to-model-using-python-code/29896>\
**Category:** Support\
**Tags:** segmentation, transforms, python\
**Created:** [June 7, 2023, 1:10pm UTC](https://discourse.slicer.org/t/apply-a-nonlinear-transform-to-model-using-python-code/29896 "2023-06-07T13:10:12Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [June 7, 2023, 5:16pm UTC](https://discourse.slicer.org/t/apply-a-nonlinear-transform-to-model-using-python-code/29896/2 "2023-06-07T17:16:37Z")

</div>

Something like the following should work for applying a nonlinear transform to a model:

```auto
straightenTransformNode = getNode('Straighten Transform')
# Get the model node that you want to transform
modelName = 'MyModel' # change this to whatever the name of your model is
modelNode = getNode(modelName)
# To apply transform to model
modelNode.SetAndObserveTransformNodeID(straightenTransformNode.GetID())
# To unapply a transform
modelNode.SetAndObserveTransformNodeID(None)

```

Separately, to invert a transform node, call `Inverse()` on it

```auto
straightenTransformNode.Inverse()

```

You might also find the following discussion helpful: [Invert transform (Elastix)](https://discourse.slicer.org/t/invert-transform-elastix/14754)

---

_[View the full topic](https://discourse.slicer.org/t/apply-a-nonlinear-transform-to-model-using-python-code/29896)._
