# Calling Python from C++

**URL:** <https://discourse.slicer.org/t/calling-python-from-c/7841>\
**Category:** Development\
**Created:** [August 1, 2019, 6:18pm UTC](https://discourse.slicer.org/t/calling-python-from-c/7841 "2019-08-01T18:18:37Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![rprueckl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rprueckl/32/4240_2.png) [@rprueckl](https://discourse.slicer.org/u/rprueckl)\
**Post date:** [August 6, 2019, 11:34am UTC](https://discourse.slicer.org/t/calling-python-from-c/7841/7 "2019-08-06T11:34:58Z")

</div>

Considering the comments from [here](https://discourse.slicer.org/t/updated-sample-code-for-calling-cli-via-c/7840/4), I reduced the code as follows, but still the question remains: can I execute the scripted module based on the following code? How would I do that?

```auto
// get module and its widget
qSlicerScriptedLoadableModule* scrModule = static_cast<qSlicerScriptedLoadableModule*>(qSlicerCoreApplication::application()->moduleManager()->module("SurfaceToolbox"));
vtkSlicerScriptedLoadableModuleLogic* moduleLogic = vtkSlicerScriptedLoadableModuleLogic::SafeDownCast(scrModule->logic());

// create scripted module node
vtkMRMLScriptedModuleNode* scrNode = vtkMRMLScriptedModuleNode::SafeDownCast(scene->CreateNodeByClass("vtkMRMLScriptedModuleNode"));
scene->AddNode(scrNode);

// set parameters
scrNode->SetParameter("connectivity", "true");

// TBD: set input/output nodes
// TBD: start execution

```

---

_[View the full topic](https://discourse.slicer.org/t/calling-python-from-c/7841)._
