# Export model to model distances as.csv

**URL:** https://discourse.slicer.org/t/export-model-to-model-distances-as-csv/18506
**Category:** Support
**Created:** [July 4, 2021, 7:27pm UTC](https://discourse.slicer.org/t/export-model-to-model-distances-as-csv/18506 "2021-07-04T19:27:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@fred](https://discourse.slicer.org/u/fred)
#### Post date: [July 4, 2021, 7:27pm UTC](https://discourse.slicer.org/t/export-model-to-model-distances-as-csv/18506/1 "2021-07-04T19:27:46Z")

</div>

Slicer 4.11 on Mac OS X.

Hi everyone,  
I’d like to export the results of the “model to model distance” extension as an .csv file for further analysis of the 3D distances. The “mesh statistics” extension only computes Min; Max; Mean; etc… but I need the entire dataset of 3D distances between the 2 models.

I never used python, but found some lines in this topic: [Model2model distance: export values of vtk file](https://discourse.slicer.org/t/model2model-distance-export-values-of-vtk-file/15633)

Yet the lines do not seem to work for me.

> > > modelNode = slicer.util.getNode(‘VTK Output File’)  
> > > distances = slicer.util.arrayFromModelPointData(modelNode,‘Absolute\_to\_BBCJG\_vtkMRMLModelNodeF’)  
> > > pandas.DataFrame(distances).to\_csv(r’~/Desktop/Model/data.csv’, index=False)

> Traceback (most recent call last):  
> File “”, line 1, in   
> NameError: name ‘pandas’ is not defined

Thank you very much in advance for your help!

---

<div class="post-metadata">

### Author: ![Fluvio\_Lobo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fluvio_lobo/32/81262_2.png) [@Fluvio\_Lobo](https://discourse.slicer.org/u/Fluvio_Lobo)
#### Post date: [July 4, 2021, 10:29pm UTC](https://discourse.slicer.org/t/export-model-to-model-distances-as-csv/18506/2 "2021-07-04T22:29:54Z")

</div>

@fred,

Regarding your code, there are few things you need to change.

1. You need to install the `pandas` Python library or module. To do this, execute the following line in the Python Interactor: `slicer.util.pip_install('pandas')` [[1](https://discourse.slicer.org/t/install-python-library-with-extension/10110)]

2. Then Import the `pandas` module by executing `import pandas` also in the Python Interactor

Now you can enter the code above but, keep in mind that some variables may not be the same as you expect. For instance;

1. `modelNode = slicer.util.getNode("VTK Output File")` you may have named the output file to something other than **VTK Output File**

2. `slicer.util.arrayFromModelPointData(modelNode,"Absolute_to_BBCJG_vtkMRMLModelNodeF")` I am not sure what `Absolute_to_BBCJG_vtkMRMLModelNodeF` is but you may need to change this to one of the variables in the VTK structure, such as: `PointToPointVector` or `PointToPointAlongX` and so on…

3. Finally, make sure you have the correct path here `pandas.DataFrame(distances).to_csv(r"~/Desktop/Model/data.csv", index=False)`

Also, I had to change all of the single quotations `'` to double `"`, I think this is a Windows/Linux thing. I am using a Windows!

Another trick that may work for you is to inspect the **VTK Output File** manually. You can always save the file as a ASCii or decompressed version of the file and open it with a text reader.

 ![ascii_version](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/f/efe5e149260ee0726e50a9a466d7948735d13184.png)

---

<div class="post-metadata">

### Author: ![fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@fred](https://discourse.slicer.org/u/fred)
#### Post date: [July 5, 2021, 6:23am UTC](https://discourse.slicer.org/t/export-model-to-model-distances-as-csv/18506/3 "2021-07-05T06:23:51Z")

</div>

Thank you Fluvio\_Lobo !

I had to install Pandas first, so the 2 first lines you provided did the job.  
Regarding the names for the output file and the variable, I used the ones I was actually working on, so everything was fine.  
And thank you for the trick with the decompressed file!
