How to detect MRI file being loaded?

Hello,

I need to log the header of the MRI file. How can I detect if an MRI file is loaded in slicer?

Thanks for your help.

If you need to do something whenever a node is added, you can listen for the slicer.vtkMRMLScene.NodeAddedEvent. Example

What kind of information is in the header depends on the file format, so you would need to figure out how your file format indicates whether the modality is MRI. Not all formats indicate this information in any standard way.