# Batch creation of mrml scenes

**URL:** <https://discourse.slicer.org/t/batch-creation-of-mrml-scenes/10861>\
**Category:** Support\
**Created:** [March 26, 2020, 7:00pm UTC](https://discourse.slicer.org/t/batch-creation-of-mrml-scenes/10861 "2020-03-26T19:00:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Masteling](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/masteling/32/13587_2.png) [@Masteling](https://discourse.slicer.org/u/Masteling)\
**Post date:** [March 26, 2020, 7:00pm UTC](https://discourse.slicer.org/t/batch-creation-of-mrml-scenes/10861/1 "2020-03-26T19:00:34Z")

</div>

I have a series of 3D ultrasounds that I converted to mhd+raw files.

I want to automate the creation of mrml scenes for all my files (\> 500 files), to make it easier to visualize by others.

Goal: import mhd+raw -\> save as .mrml

Is there any script I can use/adapt?

Thank you,  
Mariana

---

<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:** [March 26, 2020, 7:02pm UTC](https://discourse.slicer.org/t/batch-creation-of-mrml-scenes/10861/2 "2020-03-26T19:02:04Z")

</div>

These examples in the script repository should help:

[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Load\_volume\_from\_file](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Load_volume_from_file)

[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Save\_the\_scene\_into\_a\_single\_MRB\_file](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Save_the_scene_into_a_single_MRB_file)

---

<div class="post-metadata">

**Author:** ![sobiny](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sobiny/32/6375_2.png) [@sobiny](https://discourse.slicer.org/u/sobiny)\
**Post date:** [March 26, 2020, 7:43pm UTC](https://discourse.slicer.org/t/batch-creation-of-mrml-scenes/10861/3 "2020-03-26T19:43:52Z")

</div>

```
source_dir='C:\\mhddir\\'
for parent, dirnames, filenames in os.walk(source_dir):
    for filename in filenames:
        mhdfile = os.path.join(parent, filename)
        if mhdfile.endswith(".mhd"):
            [success, mhdNode] = slicer.util.loadVolume(mhdfile, returnNode=True)

sceneSaveFilename ="c:\\test.mrb"
slicer.util.saveScene(sceneSaveFilename)

```

I haven’t tested this code  
I don’t know if I understand what you mean
