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

**URL:** <https://discourse.slicer.org/t/loading-a-scalars-file-mgh-overlay-for-a-model-node-pial-via-python/9356>\
**Category:** Support\
**Tags:** registration, extensions-manager\
**Created:** [December 2, 2019, 9:26pm UTC](https://discourse.slicer.org/t/loading-a-scalars-file-mgh-overlay-for-a-model-node-pial-via-python/9356 "2019-12-02T21:26:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aping](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@Aping](https://discourse.slicer.org/u/Aping)\
**Post date:** [December 2, 2019, 9:26pm UTC](https://discourse.slicer.org/t/loading-a-scalars-file-mgh-overlay-for-a-model-node-pial-via-python/9356/1 "2019-12-02T21:26:24Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 3, 2019, 4:42am UTC](https://discourse.slicer.org/t/loading-a-scalars-file-mgh-overlay-for-a-model-node-pial-via-python/9356/3 "2019-12-03T04:42:40Z")

</div>

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

```python
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.

---

<div class="post-metadata">

**Author:** ![Aping](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@Aping](https://discourse.slicer.org/u/Aping)\
**Post date:** [December 3, 2019, 7:39pm UTC](https://discourse.slicer.org/t/loading-a-scalars-file-mgh-overlay-for-a-model-node-pial-via-python/9356/4 "2019-12-03T19:39:52Z")

</div>

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

```auto
 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.

---

<div class="post-metadata">

**Author:** ![Aping](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@Aping](https://discourse.slicer.org/u/Aping)\
**Post date:** [December 3, 2019, 7:41pm UTC](https://discourse.slicer.org/t/loading-a-scalars-file-mgh-overlay-for-a-model-node-pial-via-python/9356/5 "2019-12-03T19:41:10Z")

</div>

About version: I tested 4.8.1 and 4.10.1

---

<div class="post-metadata">

**Author:** ![Aping](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@Aping](https://discourse.slicer.org/u/Aping)\
**Post date:** [December 3, 2019, 8:13pm UTC](https://discourse.slicer.org/t/loading-a-scalars-file-mgh-overlay-for-a-model-node-pial-via-python/9356/6 "2019-12-03T20:13:29Z")

</div>

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

Best wishes,
