# ProbeVolumeWithModel produces wrong output in code

**URL:** <https://discourse.slicer.org/t/probevolumewithmodel-produces-wrong-output-in-code/22485>\
**Category:** Support\
**Created:** [March 13, 2022, 4:36pm UTC](https://discourse.slicer.org/t/probevolumewithmodel-produces-wrong-output-in-code/22485 "2022-03-13T16:36:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muhammed\_Fatih\_Talu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muhammed_fatih_talu/32/14646_2.png) [@Muhammed\_Fatih\_Talu](https://discourse.slicer.org/u/Muhammed_Fatih_Talu)\
**Post date:** [March 13, 2022, 4:36pm UTC](https://discourse.slicer.org/t/probevolumewithmodel-produces-wrong-output-in-code/22485/1 "2022-03-13T16:36:23Z")

</div>

When I use the GUI of the ProbeVolumeWithModel, there is no problem. It does great coloring.

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/9/a983f9697cdb283c4bca6feb5994dccc1439fb3c.png)

But, when I want to do the same with the following codes, it runs and produces a plane output. Why?

```auto
# Inputs
InputModelNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLModelNode")
OutputModelNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLModelNode", "Skull_Thickness")

#Parameters for ProbeVolumeWithModel
parameters = {}
parameters['InputVolume'] = DistanceMapNode.GetID()
parameters['InputModel'] = InputModelNode.GetID()
parameters['OutputModel'] = OutputModelNode.GetID()

probe = slicer.modules.probevolumewithmodel
slicer.cli.run(probe, None, parameters, wait_for_completion=True)

```

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/a/6af476b06885b3b31ab0039aa1d3d7dcf653294f.png)

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [March 13, 2022, 5:29pm UTC](https://discourse.slicer.org/t/probevolumewithmodel-produces-wrong-output-in-code/22485/2 "2022-03-13T17:29:31Z")

</div>

Check in the application log to see what’s different in the command line options when the module runs.

---

<div class="post-metadata">

**Author:** ![Muhammed\_Fatih\_Talu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muhammed_fatih_talu/32/14646_2.png) [@Muhammed\_Fatih\_Talu](https://discourse.slicer.org/u/Muhammed_Fatih_Talu)\
**Post date:** [March 13, 2022, 7:11pm UTC](https://discourse.slicer.org/t/probevolumewithmodel-produces-wrong-output-in-code/22485/3 "2022-03-13T19:11:36Z")

</div>

Steve, thanks for reply.  
First, I was excited and examined the log file (as below).  
I thought I could find the step-by-step python codes of the process done in the log file.  
However, the log file unfortunately did not have detailed content.

```auto
[DEBUG][Qt] 13.03.2022 21:36:02 [] (unknown:0) - Switch to module: "ProbeVolumeWithModel"
[DEBUG][Qt] 13.03.2022 21:36:20 [] (unknown:0) - Found CommandLine Module, target is C:/ProgramData/NA-MIC/Slicer 4.13.0-2022-02-11/bin/../lib/Slicer-4.13/cli-modules/ProbeVolumeWithModel.exe
[DEBUG][Qt] 13.03.2022 21:36:20 [] (unknown:0) - ModuleType: CommandLineModule
[DEBUG][Qt] 13.03.2022 21:36:22 [] (unknown:0) - Probe Volume With Model command line: 

C:/ProgramData/NA-MIC/Slicer 4.13.0-2022-02-11/bin/../lib/Slicer-4.13/cli-modules/ProbeVolumeWithModel.exe --outputArrayName NRRDImage C:/Users/Administrator/AppData/Local/Temp/19/Slicer/BIBHG_vtkMRMLScalarVolumeNodeE.nrrd C:/Users/Administrator/AppData/Local/Temp/19/Slicer/BIBHG_vtkMRMLModelNodeE.vtk C:/Users/Administrator/AppData/Local/Temp/19/Slicer/BIBHG_vtkMRMLModelNodeF.vtk
[DEBUG][Qt] 13.03.2022 21:36:24 [] (unknown:0) - Probe Volume With Model standard output:

Done reading the file C:/Users/Administrator/AppData/Local/Temp/19/Slicer/BIBHG_vtkMRMLScalarVolumeNodeE.nrrd
[DEBUG][Qt] 13.03.2022 21:36:24 [] (unknown:0) - Probe Volume With Model completed without errors

```

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [March 13, 2022, 7:53pm UTC](https://discourse.slicer.org/t/probevolumewithmodel-produces-wrong-output-in-code/22485/4 "2022-03-13T19:53:59Z")

</div>

Hi @Muhammed_Fatih_Talu -

Yes, this is expected - the ProbeVolumeWithModel module is a [C++ command line module](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Modules) so when you run it from the GUI your widget selections are converted into command line arguments. To call the same module from python you need to make sure your command has all the same arguments of the right types. Both ways of running the module will log the command line in the log.

---

<div class="post-metadata">

**Author:** ![Muhammed\_Fatih\_Talu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muhammed_fatih_talu/32/14646_2.png) [@Muhammed\_Fatih\_Talu](https://discourse.slicer.org/u/Muhammed_Fatih_Talu)\
**Post date:** [March 14, 2022, 6:00am UTC](https://discourse.slicer.org/t/probevolumewithmodel-produces-wrong-output-in-code/22485/5 "2022-03-14T06:00:49Z")

</div>

I solved the problem.  
I was not getting the correct ID of InputModelNode.

instead of slicer.mrmlScene.GetFirstNodeByClass(“vtkMRMLModelNode”),  
I used slicer.mrmlScene.GetFirstNodeByName(“InputModel”).  
It runs perfect 🙂  
Thanks every body.

---

<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 14, 2022, 12:55pm UTC](https://discourse.slicer.org/t/probevolumewithmodel-produces-wrong-output-in-code/22485/6 "2022-03-14T12:55:02Z")

</div>

Image slices are displayed in 3D views as model nodes, therefore the first 3 model nodes are typically these slice plane nodes.

@pieper what do you think about adding a flag to GetFirstNodeByName method to include/exclude hidden nodes and by default make hidden nodes excluded? This would change the behavior of the method by default, but since this is a high-level convenience function, the expected behavior is probably to not consider hidden nodes.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [March 14, 2022, 1:24pm UTC](https://discourse.slicer.org/t/probevolumewithmodel-produces-wrong-output-in-code/22485/7 "2022-03-14T13:24:08Z")

</div>

> [@lassoan](#):
>
> @pieper what do you think about adding a flag to GetFirstNodeByName method to include/exclude hidden nodes and by default make hidden nodes excluded? This would change the behavior of the method by default, but since this is a high-level convenience function, the expected behavior is probably to not consider hidden nodes.

Yes, those convenience methods (also `getNode` in python) seem to regularly lead to some confusion; making them behave better could help. Maybe in `slicer.util` we should provide a `pickNode` method that pops up a gui node combo box and use that in the script repository instead of teaching people to use the less reliable methods.

---

<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 14, 2022, 4:12pm UTC](https://discourse.slicer.org/t/probevolumewithmodel-produces-wrong-output-in-code/22485/8 "2022-03-14T16:12:33Z")

</div>

This is a very interesting discussion, I’ve started a new topic for it to get some more visibility:

> [@Make it easier to select input nodes for Python scripts](https://discourse.slicer.org/t/make-it-easier-to-select-input-nodes-for-python-scripts/22498):
>
> While discussing a [problem due to selecting the wrong input node in a Python script](https://discourse.slicer.org/t/probevolumewithmodel-produces-wrong-output-in-code/22485), we started to brainstorm about how to make it easier to select input nodes for Python scripts. The first idea was to [change vtkMRMLScene::GetFirstNodeByName to return non-hidden node](https://discourse.slicer.org/t/probevolumewithmodel-produces-wrong-output-in-code/22485/6) by default. Then @pieper raised the idea of [adding a slicer.util.pickNode method to show a popup where the user can select a node](https://discourse.slicer.org/t/probevolumewithmodel-produces-wrong-output-in-code/22485/7). I’ve created this topic to make this discussion more visible and get some more ideas and feedback …
