Script to display a table

Sorry if this is a dumb question, but I’m very new to slicer. I’m trying to code a python module that can display coordinates from a csv file. I know that you can do this with properly formatted csv files using the markup module, but I’d like to know how to do this from scratch. The goal is to create a module that allows me to select a csv file I upload to Slicer, append the required header, and then display the points.

Currently, I’m getting stuck on two steps. The first is figuring out how to get script to read whatever file I select with the ctkPathLineEdit widget. The second is figuring out how to display the data points after the csv file has been edited (this is the one I need the most help with). Any tips or hints?

Option A

The most flexible and powerful option is to to save the coordinates in a json file:

{"@schema": "",
"markups": [{"type": "Fiducial", "coordinateSystem": "LPS", "controlPoints": [
    { "label": "F-1", "position": [-53.388409961685827, -73.33572796934868, 0.0] },
    { "label": "F-2", "position": [49.8682950191571, -88.58955938697324, 0.0] },
    { "label": "F-3", "position": [-25.22749042145594, 59.255268199233729, 0.0] }

You can load using:

markupsNode = slicer.util.loadMarkups("/path/to/MyMarkups.mkp.json")

Option B

If you only need to specify coordinates, then you can create a csv file with a few columns:


You can load it like this:

markupsNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsCurveNode")

More information

1 Like

Thanks this helped a lot!

Is there anyway to edit the text for the label displayed in the scene so it doesn’t say “MarkupsCurve”?