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

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!

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

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

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.

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

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