Python conversion between model and segment

thanks for providing this great Software.

I am trying to change Models to Segments and Segments to Models using Python. This can easily be done using the GUI.
Model to Segmentation

Segmentation to Model


This is what I have found so far.
Converting Models to Segments

Create segmentation

segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
addedSegmentID = segmentationNode.GetSegmentation().AddEmptySegment("Segment")

modelNode = slicer.util.getNode('Model')
segmentationNode = slicer.util.getNode('Segmentation')

slicer.modules.segmentations.logic().CreateSegmentFromModelNode(modelNode, segmentationNode)

The segmentation is then empty somehow.

Thanks in advance

I would recommend to use higher-level (import/export) methods of segmentations logic. See examples in the script repository.