Loading a Scalars file (.mgh) Overlay for a Model Node (.pial) via Python

Hi slicer experts,
I am working to load >100 .mgh files overlay model which I want to make a video for demo.
I can load the model by:
model = slicer.util.loadModel(‘lh.pial’)
But, how to load the surface file (.mgh) overlay the model. I tested these command but failed.
surface = slicer.util.loadScalarOverlay(‘lh_filed.mgh’)
I found the function (slicer.util.openAddScalarOverlayDialog()) works, but you had to select the (.mgh) file manually.
Is there a function can load .mgh automatically to overlay the loaded model?

Best wishes,

Operating system: Centos 7
Slicer version: 4.8.1
Expected behavior:
Actual behavior:

It seems that loadScalarOverlay convenience function does not expose the option to specify referenced node.

modelNode = slicer.util.loadModel(surfaceFilename)
slicer.util.loadNodeFromFile(overlayFilename, 'ScalarOverlayFile', {'modelNodeId': modelNode.GetID()})

(this above works on recent Slicer Preview Releases, for stable release, you need to specify returnNode=True for loadModel and it returns a success flag and a model node)

I’ll update slicer.util.loadScalarOverlay to take an optional model node ID.

Thanks, Iassoan.
I found it still cannot overlay.
I run as follows:

 modelNode = slicer.util.loadModel('lh.pial',  returnNode=True) % it can load the model to 3DSlicer, but I fount the modelNode did not have attribution GetID
 slicer.util.loadNodeFromFile(overlayFilename, 'ScalarOverlayFile', {'modelNodeId': modelNode.GetID()})
% it failed.

The error message as follows:
AttributeError: ‘tuple’ object has no attribute ‘GetID’
Can you tell me how to deal with the problem? how to obtain the node ID as you said above?

Thanks in advance.

About version: I tested 4.8.1 and 4.10.1

Thanks Iassoan. I update the version and it works now.
Thanks again.

Best wishes,

1 Like