# How to make segments from vtkMRMLModelNode by code

**URL:** <https://discourse.slicer.org/t/how-to-make-segments-from-vtkmrmlmodelnode-by-code/10389>\
**Category:** Support\
**Created:** [February 22, 2020, 1:10am UTC](https://discourse.slicer.org/t/how-to-make-segments-from-vtkmrmlmodelnode-by-code/10389 "2020-02-22T01:10:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![apparrilla](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/apparrilla/32/9230_2.png) [@apparrilla](https://discourse.slicer.org/u/apparrilla)\
**Post date:** [February 22, 2020, 1:10am UTC](https://discourse.slicer.org/t/how-to-make-segments-from-vtkmrmlmodelnode-by-code/10389/1 "2020-02-22T01:10:05Z")

</div>

Hi,  
I have some ModelNodes from .vtk files attacked to lineartransforms.  
With this code i get new segments for each model in segmentation but with wrong location.  
How to fix segments position?

> name = model.GetName()  
> abstransform = model.GetParentTransformNode().GetTransformFromParent()  
> applyTransform = vtk.vtkTransformPolyDataFilter()  
> applyTransform.SetTransform(abstransform )  
> applyTransform.SetInputData(model.GetPolyData())  
> applyTransform.Update()  
> surface = applyTransform.GetOutput()  
> # Remove point arrays to make sure they don’t affect display color  
> while surface.GetPointData().GetNumberOfArrays()\>0:  
> surface.GetPointData().RemoveArray(0)  
> segmentation.AddSegmentFromClosedSurfaceRepresentation(surface, name, [1,1,1])

Thanks on advance!

---

<div class="post-metadata">

**Author:** ![Juicy](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Juicy](https://discourse.slicer.org/u/Juicy)\
**Post date:** [February 22, 2020, 2:41am UTC](https://discourse.slicer.org/t/how-to-make-segments-from-vtkmrmlmodelnode-by-code/10389/2 "2020-02-22T02:41:55Z")

</div>

I don’t understand exactly what you are trying to do but would hardening the transform help?

Take a look at [this page.](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#How_to_harden_a_transform_.3F) For an example of how to harden the transform using python.

Otherwise perhaps you have to also put the new segments in the linear transform so they also end up in the same location as the models?

---

<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:** [February 22, 2020, 3:11am UTC](https://discourse.slicer.org/t/how-to-make-segments-from-vtkmrmlmodelnode-by-code/10389/3 "2020-02-22T03:11:04Z")

</div>

> [@apparrilla](#):
>
> With this code i get new segments for each model in segmentation but with wrong location.

If you load the .vtk files as models (using File / Add data) do they appear at the correct position?

---

<div class="post-metadata">

**Author:** ![apparrilla](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/apparrilla/32/9230_2.png) [@apparrilla](https://discourse.slicer.org/u/apparrilla)\
**Post date:** [February 22, 2020, 9:34am UTC](https://discourse.slicer.org/t/how-to-make-segments-from-vtkmrmlmodelnode-by-code/10389/4 "2020-02-22T09:34:16Z")

</div>

> [@lassoan](#):
>
> If you load the .vtk files as models (using File / Add data) do they appear at the correct position?

No, they appear but in wrong position.

---

<div class="post-metadata">

**Author:** ![apparrilla](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/apparrilla/32/9230_2.png) [@apparrilla](https://discourse.slicer.org/u/apparrilla)\
**Post date:** [February 22, 2020, 10:27am UTC](https://discourse.slicer.org/t/how-to-make-segments-from-vtkmrmlmodelnode-by-code/10389/5 "2020-02-22T10:27:43Z")

</div>

> [@Juicy](#):
>
> Otherwise perhaps you have to also put the new segments in the linear transform so they also end up in the same location as the models?

I tried it before, but individual segments are not transformable nodes.  
To harden model transform works right.  
Thanks so much.
