Python Planar Contours to Closed Surface

Operating system: Win10
Slicer version: 4.11


I’m looking to convert RTSTRUCT contours to STL files in a Python script.
If there is a simple robust path someone can point to, then great, otherwise what I have seen
that looks promising is from a 2019 discussion pointing to a conversion rule class in SlicerRT.
(Link to the code).

I’m quite new to Slicer and Python connections to it (and conversion rules), and I’m not sure how to find Python binding names. Looking for something like vtkPlanarContourToClosedSurfaceConversionRule, I don’t see anything in the Python interactor autocomplete that mentions PlanarContour, but perhaps I have not found the right ‘path’ to get to it. I’ve tried mainly through and There are several similar conversion rules available from the slicer object, e.g. slicer.vtkBinaryLabelmapToClosedSurfaceConversionRule. Does the rule need to be registered somehow, or is it not available in current releases?

I’ve tried in Slicer 4.11 and in preview 4.13, both on Windows with SlicerRT extension installed.

Thanks in advance for any help

I suggest you take a look at this script. The only thing you need to change is that instead of binary labelmaps you want to convert into closed surface and instead of nrrd you want to save to STL.

BTW, welcome @darcymason :+1:

As an aside you’ll see that a lot of the dicom infrastructure in Slicer assumes you are working in Slicer’s python which historically was different from regular python. But these days we’ve been able to re-sync things so that most pip packages ‘just work’ in Slicer. This makes us think we might refactor Slicer dicom code for more general purpose use, but we haven’t put the work in for that yet.

Thanks for the quick replies, and for the welcome, @pieper :grin:

I had seen that before but got stuck on the conversion rule seen in the discussion I linked, but per your suggestion, it seems I could use segNode.CreateClosedSurfaceRepresentation(). It appears there are no arguments to the function, so is there a way I could specify the particular rule (or does that happen to point to the one I’m interested in)? And … a quick pointer to how to adjust settings prior (e.g. smoothing) would be very helpful.

Thanks again