# Model2model distance: export values of vtk file

**URL:** <https://discourse.slicer.org/t/model2model-distance-export-values-of-vtk-file/15633>\
**Category:** Support\
**Tags:** python, 3d-model\
**Created:** [January 22, 2021, 4:11pm UTC](https://discourse.slicer.org/t/model2model-distance-export-values-of-vtk-file/15633 "2021-01-22T16:11:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nabilgh](https://avatars.discourse-cdn.com/v4/letter/n/a87d85/32.png) [@nabilgh](https://discourse.slicer.org/u/nabilgh)\
**Post date:** [January 22, 2021, 4:11pm UTC](https://discourse.slicer.org/t/model2model-distance-export-values-of-vtk-file/15633/1 "2021-01-22T16:11:30Z")

</div>

I’m using Slicer 4.11 to compare the deviation between 2 dental models.  
I used the model2model distance extension to compare the models.  
The output created was VTK Output File.  
I would like to get the values in mm in an array so I used the following lines in the python interactor:

> modelNode = slicer.util.getNode(‘VTK Output File’)  
> distances = slicer.util.arrayFromModelPointData(modelNode,‘testArray’)

However I am getting the following error:

> > > > distances = slicer.util.arrayFromModelPointData(modelNode,‘testArray’)  
> > > > Traceback (most recent call last):  
> > > > File “”, line 1, in   
> > > > File “C:\Users\User\AppData\Local\NA-MIC\Slicer 4.11.20200930\bin\Python\slicer\util.py”, line 1293, in arrayFromModelPointData  
> > > > narray = vtk.util.numpy\_support.vtk\_to\_numpy(arrayVtk)  
> > > > File “C:\Users\User\AppData\Local\NA-MIC\Slicer 4.11.20200930\bin\Lib\site-packages\vtkmodules\util\numpy\_support.py”, line 216, in vtk\_to\_numpy  
> > > > typ = vtk\_array.GetDataType()  
> > > > AttributeError: ‘NoneType’ object has no attribute ‘GetDataType’

Any help is aprreciated. 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:** [January 22, 2021, 4:15pm UTC](https://discourse.slicer.org/t/model2model-distance-export-values-of-vtk-file/15633/2 "2021-01-22T16:15:55Z")

</div>

You provided an incorrect array name. In recent Slicer versions, this error message is improved: you get the list of available arrays. You can also look up the available array names in Models module / Display / Scalars.

---

<div class="post-metadata">

**Author:** ![nabilgh](https://avatars.discourse-cdn.com/v4/letter/n/a87d85/32.png) [@nabilgh](https://discourse.slicer.org/u/nabilgh)\
**Post date:** [January 22, 2021, 4:30pm UTC](https://discourse.slicer.org/t/model2model-distance-export-values-of-vtk-file/15633/3 "2021-01-22T16:30:11Z")

</div>

thank you it worked. How do I export the array to a file / excel sheet?

---

<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:** [January 22, 2021, 4:41pm UTC](https://discourse.slicer.org/t/model2model-distance-export-values-of-vtk-file/15633/4 "2021-01-22T16:41:35Z")

</div>

You get the values as a numpy array, so you can already do all the statistics that Excel can do using a few lines of Python code (using numpy, pandas, etc.). To browse values in a nicer environment than the plain Python console, you can use Jupyter notebooks or JupyterLab (using [SlicerJupyter extension](https://github.com/Slicer/SlicerJupyter)).

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/5/85564b64df6e8cf6c8331c247da456bf1c58f9ee.png)

Anyway, you can save a numpy array into csv file format that Excel can load, for example using this command `pandas.DataFrame(distances).to_csv(filename)`.

---

<div class="post-metadata">

**Author:** ![sfglio](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sfglio/32/3346_2.png) [@sfglio](https://discourse.slicer.org/u/sfglio)\
**Post date:** [January 23, 2021, 8:58pm UTC](https://discourse.slicer.org/t/model2model-distance-export-values-of-vtk-file/15633/5 "2021-01-23T20:58:44Z")

</div>

I am a complete newbie to python scripting however I would like to run the

modelNode = slicer.util.getNode(‘VTK Output File’)  
distances = slicer.util.arrayFromModelPointData(modelNode,‘testArray’)

and I always get

> > > modelNode = slicer.util.getNode(‘VTK Output File’)  
> > > File “”, line 1  
> > > modelNode = slicer.util.getNode(‘VTK Output File’)  
> > > ^  
> > > SyntaxError: invalid character in identifier

I have created my vtk output file, but do I need to import it anyway?

---

<div class="post-metadata">

**Author:** ![nabilgh](https://avatars.discourse-cdn.com/v4/letter/n/a87d85/32.png) [@nabilgh](https://discourse.slicer.org/u/nabilgh)\
**Post date:** [January 23, 2021, 10:28pm UTC](https://discourse.slicer.org/t/model2model-distance-export-values-of-vtk-file/15633/6 "2021-01-23T22:28:11Z")

</div>

I’m also a newbie in scripting but I managed to follow @lassoan instructions above. You cannot use the “testArray” name for your array. You have to go to Models section, select you VTK Output File then navigate to Display/Scalars and choose a name from the active scalar list. For me this code worked:

> modelNode = slicer.util.getNode(VTK Output File)
> 
> distances = slicer.util.arrayFromModelPointData(modelNode,‘PointToPointVector’)
> 
> pandas.DataFrame(distances).to\_csv(r’C:\Users\user\Desktop\data.csv’, index=False)

The last line of code enables the export to csv file. You’ll get 3 columns of values in the sheet. However i’m not sure if every column refers to a dimension (x,y,z).

---

<div class="post-metadata">

**Author:** ![sfglio](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sfglio/32/3346_2.png) [@sfglio](https://discourse.slicer.org/u/sfglio)\
**Post date:** [January 24, 2021, 9:03pm UTC](https://discourse.slicer.org/t/model2model-distance-export-values-of-vtk-file/15633/7 "2021-01-24T21:03:35Z")

</div>

Thank you for your quick reply however I failed on MacOS specific spellings when copying the code, i.e.  
the mistake was the incorrectly converted ’ when pasting the code.

modelNode = slicer.util.getNode(‘VTK Output File’)

and to export on mac:  
pandas.DataFrame(distances).to\_csv(r’~/Desktop/whatever/data.csv’, index=False)

Anyway, the question remains whether “Signed” or “PointToPointVector” is more suitable to describe distances between to meshes (e.g. two dental models).  
So if I only want to describe the dimension of a vertical displacement between two models then second column (y) of the Pointtopointvector would fit best???  
If I am interested in the maximum deviations (regardless of the axis) then “signed” would also fit…keeping in mind that I can have a look at the distance map to see where max. deviations were found.

Unfortunately it makes a difference which scalar you choose in terms of “mm” (signed vs. pointtopointvector)!  
Other software to create distance maps where a scale bar is present seem to rely on “signed”…

---

<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:** [January 24, 2021, 10:33pm UTC](https://discourse.slicer.org/t/model2model-distance-export-values-of-vtk-file/15633/8 "2021-01-24T22:33:44Z")

</div>

I would recommend to create a new topic to get advice on which metric to use. Add a few annotated images because it is not possible to explain what exactly you would like to quantify in plain text.
