Markups ROI cannot be loaded from JSON file

System: WIN 10
Slicer version: Slicer 5.0.3

Hi There,
I’m trying to save markups ROI node as a markups JSON file programmatically.

First, I added a markups ROI node to the 3d view using ‘Markups’ module manually.
And then, I saved the markups ROI node to a JSON file. I referenced the code snippet in the Script repository to do that: Save markups to file

As shown in the figure below, here is the code I executed in the Python console:

markupsNode = slicer.util.getNode('R')
slicer.util.saveNode(markupsNode, + "/" + "MyMarkups.mrk.json")

However, When I trying to load the markups from the JSON file, the ROI cannot be reloaded into 3D view, it is displayed as a dot instead of the box:

Here is the JSON file automatically created by the code snippet (MyMarkups.mrk.json):

    "@schema": "",
    "markups": [
            "type": "ROI",
            "coordinateSystem": "LPS",
            "coordinateUnits": "mm",
            "locked": false,
            "fixedNumberOfControlPoints": false,
            "labelFormat": "%N-%d",
            "lastUsedControlPointNumber": 1,
            "controlPoints": [
                    "id": "1",
                    "label": "R-1",
                    "description": "",
                    "associatedNodeID": "",
                    "position": [-46.1154670715332, -0.0, -11.705148696899414],
                    "orientation": [-1.0, -0.0, -0.0, -0.0, -1.0, -0.0, 0.0, 0.0, 1.0],
                    "selected": true,
                    "locked": false,
                    "visibility": true,
                    "positionStatus": "defined"
            "measurements": [
                    "name": "volume",
                    "enabled": false,
                    "units": "cm3",
                    "printFormat": "%-#4.4g%s"
            "display": {
                "visibility": true,
                "opacity": 1.0,
                "color": [0.4, 1.0, 0.0],
                "selectedColor": [0.9372549019607843, 0.34901960784313726, 0.3843137254901961],
                "activeColor": [0.4, 1.0, 0.0],
                "propertiesLabelVisibility": true,
                "pointLabelsVisibility": false,
                "textScale": 3.0,
                "glyphType": "Sphere3D",
                "glyphScale": 1.0,
                "glyphSize": 5.0,
                "useGlyphScale": true,
                "sliceProjection": false,
                "sliceProjectionUseFiducialColor": true,
                "sliceProjectionOutlinedBehindSlicePlane": false,
                "sliceProjectionColor": [1.0, 1.0, 1.0],
                "sliceProjectionOpacity": 0.6,
                "lineThickness": 0.2,
                "lineColorFadingStart": 1.0,
                "lineColorFadingEnd": 10.0,
                "lineColorFadingSaturation": 1.0,
                "lineColorFadingHueOffset": 0.0,
                "handlesInteractive": true,
                "translationHandleVisibility": true,
                "rotationHandleVisibility": false,
                "scaleHandleVisibility": true,
                "interactionHandleScale": 3.0,
                "snapMode": "toVisibleSurface"

I found that the JSON file is missing the following keys under the “markups”:

"center": ,
"orientation": ,
"size": ,

Why is this happening? How do I need to modify the code snippet so that it can automatically generates a full JSON file containing the above keys to be able to reload the ROI box in the 3d view?

Thank you very much!

Another thing I’ve found is that after I execute the above code, even if I click the ‘SAVE’ button to regenerate a new JSON file, it’s still incomplete as shown above, which causes when I import the ‘mrml’ file to reload the scene, the ROI box can not be loaded.
Is there any specific solutions?
Thank you so much!

Thanks! I’m taking a look into it.

1 Like

This issue should be fixed with this PR: BUG: Ensure default JSON storage node is used in qSlicerMarkupsWriter by Sunderlandkyl · Pull Request #6551 · Slicer/Slicer · GitHub.

You can call “AddDefaultStorageNode()” as a workaround in Slicer 5.0.3:

markupsNode = slicer.util.getNode('R')
slicer.util.saveNode(markupsNode, + "/" + "MyMarkups.mrk.json")
1 Like

It worked, thanks a lot for your help!

1 Like