# How to generate a .seg.nrrd file out of multiple STLs with Python?

**URL:** <https://discourse.slicer.org/t/how-to-generate-a-seg-nrrd-file-out-of-multiple-stls-with-python/34607>\
**Category:** Development\
**Created:** [February 28, 2024, 11:20pm UTC](https://discourse.slicer.org/t/how-to-generate-a-seg-nrrd-file-out-of-multiple-stls-with-python/34607 "2024-02-28T23:20:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dzemal](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@Dzemal](https://discourse.slicer.org/u/Dzemal)\
**Post date:** [February 28, 2024, 11:20pm UTC](https://discourse.slicer.org/t/how-to-generate-a-seg-nrrd-file-out-of-multiple-stls-with-python/34607/1 "2024-02-28T23:20:07Z")

</div>

Hi together,  
I’m trying to write a code snippet in Python for a pipeline that should generate a .seg.nrrd file by using the actual DICOM and the segmented STLs. In Slicer, I have performed this by using the module ‘Segmentations’ → Import models (one by one) → Right-click on the created segmentation node and export it as a .seg.nrrd file. Are there any existing python modules or functions, which can perform exactly this operation?

Thanks for any clue!

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [February 28, 2024, 11:33pm UTC](https://discourse.slicer.org/t/how-to-generate-a-seg-nrrd-file-out-of-multiple-stls-with-python/34607/2 "2024-02-28T23:33:41Z")

</div>

You can perhaps take a look at SlicerMorph’s ImportSurfaceToSegment module:

> <https://github.com/SlicerMorph/SlicerMorph/blob/master/ImportSurfaceToSegment/ImportSurfaceToSegment.py>

---

<div class="post-metadata">

**Author:** ![Dzemal](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@Dzemal](https://discourse.slicer.org/u/Dzemal)\
**Post date:** [February 29, 2024, 4:48am UTC](https://discourse.slicer.org/t/how-to-generate-a-seg-nrrd-file-out-of-multiple-stls-with-python/34607/3 "2024-02-29T04:48:52Z")

</div>

Thank you for the fast reply, I will take a closer look and write back if it has solved my problem.

---

<div class="post-metadata">

**Author:** ![Dzemal](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@Dzemal](https://discourse.slicer.org/u/Dzemal)\
**Post date:** [February 29, 2024, 5:51am UTC](https://discourse.slicer.org/t/how-to-generate-a-seg-nrrd-file-out-of-multiple-stls-with-python/34607/4 "2024-02-29T05:51:33Z")

</div>

I’ve tested the module in slicer and it does exactly what I need, but I can just load one STL at once. Is there a way to load mutliple STLs and create a segmentation tree out of this STLs instead of a single segmenation node? In other words, I have the right and left femur as well as the left and right tibia and fibula saved in separated STL files. Now I need one segmentation (-tree) which I can export as a .seg.nrrd file.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [February 29, 2024, 4:30pm UTC](https://discourse.slicer.org/t/how-to-generate-a-seg-nrrd-file-out-of-multiple-stls-with-python/34607/5 "2024-02-29T16:30:26Z")

</div>

You can copy/paste segments from different segmentations. Our module doesn’t do that, but you can look into the script library for examples. [Script repository — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#segmentations)

---

<div class="post-metadata">

**Author:** ![Dzemal](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@Dzemal](https://discourse.slicer.org/u/Dzemal)\
**Post date:** [March 1, 2024, 5:06am UTC](https://discourse.slicer.org/t/how-to-generate-a-seg-nrrd-file-out-of-multiple-stls-with-python/34607/6 "2024-03-01T05:06:03Z")

</div>

Thanks again, the script repository might be helpful. I’ll give it a try and keep you updated.
