# Path of image node

**URL:** <https://discourse.slicer.org/t/path-of-image-node/799>\
**Category:** Development\
**Created:** [August 1, 2017, 1:28pm UTC](https://discourse.slicer.org/t/path-of-image-node/799 "2017-08-01T13:28:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [August 1, 2017, 1:28pm UTC](https://discourse.slicer.org/t/path-of-image-node/799/1 "2017-08-01T13:28:17Z")

</div>

I needed to pass a path to DICOM file to a certain CLI module because that module needed metadata from the header. But to get the path depends on how the node was loaded, via drag-drop or via DICOM browser. Here is a function which works for both cases:

```
def PathFromNode(self, node):
  storageNode=node.GetStorageNode()
  if storageNode is not None:
      filepath=storageNode.GetFullNameFromFileName()
  else:
      instanceUIDs=node.GetAttribute('DICOM.instanceUIDs').split()
      filepath=slicer.dicomDatabase.fileForInstance(instUids[0])
  return filepath

# example invocation
node=slicer.util.getFirstNodeByName('volume1')
path=self.PathFromNode(node)
print "DICOM path="+path
```

---

<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:** [August 2, 2017, 3:03am UTC](https://discourse.slicer.org/t/path-of-image-node/799/2 "2017-08-02T03:03:32Z")

</div>

Thank you, it’s useful example. Could you please add it to the [script repository](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository)?

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [August 2, 2017, 3:17pm UTC](https://discourse.slicer.org/t/path-of-image-node/799/3 "2017-08-02T15:17:00Z")

</div>

Added:  
[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How\_to\_get\_path\_and\_filename\_of\_a\_loaded\_DICOM\_volume.3F](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How_to_get_path_and_filename_of_a_loaded_DICOM_volume.3F)
