Extensions upgrade to Python3

Hi all,

Our extension (GeodesicSlicer) does not work in the last version of Slicer (4.11.20200903) because it needs to be ported for python3. I have to do that in a couple of days (or may I have to wait the Slicer5?).
But even if I upgraded it for Python 3, is it possible to keep a version compatible with the previous version of Slicer (and thus Python2, if yes, how to do that)?

Thanks,

Frederic

What seems to work best for most extensions is to create a separate branch for each Slicer major.minor release:

  • create a 4.10 branch from your current master (if you want to make further fixes or improvements in this version, you can do that in this branch)
  • update your s4ext file for SLicer-4.10 to use this branch (in https://github.com/Slicer/ExtensionsIndex/blob/4.10/GeodesicSlicer.s4ext, change master to 4.10)
  • make all the necessary changes master branch to make your extension work in the current Slicer version

See for example how it is done for MarkupsToModels:

1 Like

Looking at the migration guide may also be helpful. See https://www.slicer.org/wiki/Documentation/Nightly/Developers/Tutorials/MigrationGuide#Python_2_to_Python_3

1 Like

Thanks @lassoan and @jcfr for your valuable comments.

The first step is done, Now I have to make the changes to work with Python 3.

Best.

I allow myself another question, if you want I can create another post.

When I use your script @lassoan ( ExtractSkin.py , I obtain the wrong orientation (cf. pic where the yellow nose is normally in anterior) of my model.

Do you now why?Sans titre

Thanks.

I got it. It was a coordinate problem.
For the next one with the same issue, you just have to place this code (here in python) when you create you object.stl:

writer.SetHeader("Name of the output. SPACE=RAS")

GeodesicSlicer is now ready for Slicer 4.11!

1 Like

Thanks for the update. I’ve updated the example script to export the mesh in a simpler way, by calling:

slicer.vtkSlicerSegmentationsModuleLogic.ExportSegmentsClosedSurfaceRepresentationToFiles(
  "c:/tmp", segmentationNode, None, "STL")