How to convert segmentation to stl

hi
what I’m trying to do is to use this conversion by code:

ExportSegmentsClosedSurfaceRepresentationToStlFiles

but I just don’t understand how.

I also want to mersh the segmentations
like in the img.