# saveNode not working properly

**URL:** https://discourse.slicer.org/t/savenode-not-working-properly/16309
**Category:** Development
**Created:** [March 2, 2021, 3:01pm UTC](https://discourse.slicer.org/t/savenode-not-working-properly/16309 "2021-03-02T15:01:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![user20s](https://avatars.discourse-cdn.com/v4/letter/u/da6949/32.png) [@user20s](https://discourse.slicer.org/u/user20s)
#### Post date: [March 2, 2021, 3:01pm UTC](https://discourse.slicer.org/t/savenode-not-working-properly/16309/1 "2021-03-02T15:01:22Z")

</div>

Hi. I am trying to use the python interactor tool to make some resampling automatic using the module brainresample.  
I have a code that loads the volumes, loads a transform and then gives parameters and calls the module. I am pretty sure this works all fine.

Before setting up the parameters, I create a new node using “AddNewNodeByClass”, and then I want to save the new node as nifti.

> ```
> resampledNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLLabelMapVolumeNode')
> parameters = {'inputVolume': itemCT, 'referenceVolume': itemMR, 'outputVolume': resampledNode, 'warpTransform': itemTransform, 'interpolationMode': 'Linear'}
> 
> slicer.cli.run(slicer.modules.brainsresample, None, parameters)    
> slicer.util.saveNode(resampledNode, output_filename)
> 
> ```

I try to run this piece of code (with the previous part defining the volumes and all) as an external file using: ./Slicer --no-main-window --python-script /home/user/Desktop/test\_3D\_slicer.py. It seems to run the module ok (Resample Image (BRAINS) completed without errors) but then does not save the new image.  
What’s strange is that if I input my code line by line in the python interactor (CTRL+3), it works and saves the new image. I wouldn’t want to do that though since the python file contains a for loop and it would just be easier if I could manage it through the external .py file.

Does anybody know why this happens?

---

<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 2, 2021, 3:03pm UTC](https://discourse.slicer.org/t/savenode-not-working-properly/16309/2 "2021-03-02T15:03:28Z")

</div>

You need to use [`runSync`](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html?highlight=runsync#slicer.cli.runSync), otherwise you save the output node before CLI execution is completed.

---

<div class="post-metadata">

### Author: ![user20s](https://avatars.discourse-cdn.com/v4/letter/u/da6949/32.png) [@user20s](https://discourse.slicer.org/u/user20s)
#### Post date: [March 2, 2021, 4:49pm UTC](https://discourse.slicer.org/t/savenode-not-working-properly/16309/4 "2021-03-02T16:49:44Z")

</div>

@lassoan Thanks! That fixed it.
