# Save a tree of centerline curves to json files using Python

**URL:** https://discourse.slicer.org/t/save-a-tree-of-centerline-curves-to-json-files-using-python/36574
**Category:** Development
**Tags:** centerlines
**Created:** [June 3, 2024, 2:32pm UTC](https://discourse.slicer.org/t/save-a-tree-of-centerline-curves-to-json-files-using-python/36574 "2024-06-03T14:32:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ruili](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@ruili](https://discourse.slicer.org/u/ruili)
#### Post date: [June 3, 2024, 2:32pm UTC](https://discourse.slicer.org/t/save-a-tree-of-centerline-curves-to-json-files-using-python/36574/1 "2024-06-03T14:32:43Z")

</div>

Hello,

I have created a tree of centerline curves using functions from the “Extract Centerline” module, and now I want to save the curves in a file structure that can reflect the tree structure. In Slicer, I can do this by right click the stem curve → “Export to file…” → Check all the options.  
 ![Screenshot 2024-06-03 at 15.24.27](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/3/b3d0d76a91429a4225d31bb63afcae66ceecc7a7.png)  
 ![Screenshot 2024-06-03 at 15.25.01](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/f/ef7b2021893f7d665d165ef0f2a4e1f418ad36c3.png)

This will save my curves in a folder structure that looks like this:

 ![Screenshot 2024-06-03 at 15.31.09](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/e/7e1a0a01b2220ba9499f865db075023d56ea8b5c.png)

Now I wonder if there is a python command to do this easily as well? It will be great to add this to my automatic code that runs the centerline extraction.

Many 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: [June 3, 2024, 3:41pm UTC](https://discourse.slicer.org/t/save-a-tree-of-centerline-curves-to-json-files-using-python/36574/2 "2024-06-03T15:41:50Z")

</div>

This [code snippet in the script repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#save-files-to-directory-structure-matching-subject-hierarchy-folders) implements what you described.
