# Create a vtkMRMLModelNode from a polyData

**URL:** https://discourse.slicer.org/t/create-a-vtkmrmlmodelnode-from-a-polydata/8679
**Category:** Development
**Created:** [October 5, 2019, 6:27am UTC](https://discourse.slicer.org/t/create-a-vtkmrmlmodelnode-from-a-polydata/8679 "2019-10-05T06:27:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![danial](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/danial/32/4888_2.png) [@danial](https://discourse.slicer.org/u/danial)
#### Post date: [October 5, 2019, 6:27am UTC](https://discourse.slicer.org/t/create-a-vtkmrmlmodelnode-from-a-polydata/8679/1 "2019-10-05T06:27:59Z")

</div>

Operating system: macOS 10.146  
Slicer version: 4.10.2

Hello,

I want to create a vtkMRMLModelNode and display it in slicer, i did it like this :

```
vtkNew<vtkMRMLModelNode> mesh;
mesh->SetAndObservePolyData(poly);
mesh->CreateDefaultDisplayNodes();
mesh->SetName(nameOfNode.c_str());
this->mrmlScene()->AddNode(mesh.GetPointer());

```

> Blockquote vtkMRMLModelNode::CreateDefaultDisplayNodes failed: scene is invalid  
> error: [/RealTimeAblation/Slicer/Slicer-SuperBuild/Slicer-build/bin/Slicer.app/Contents/MacOS/./Slicer] exit abnormally - Report the problem.  
> 09:49:38: /Slicer/Slicer-SuperBuild/Slicer-build/Slicer exited with code 1

Can you help me to solve this problem, please ?

Thanks for your help.

---

<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: [October 5, 2019, 12:14pm UTC](https://discourse.slicer.org/t/create-a-vtkmrmlmodelnode-from-a-polydata/8679/2 "2019-10-05T12:14:39Z")

</div>

The warning is because you need to add the model node to scene before calling CreateDisplayNodes (because display nodes must be added to the same scene).

The crash is probably because scene is nullptr.

You can simplify things a bit, too:

```python
vtkMRMLModelNode* mesh = this->mrmlScene()->AddNewNodeByClass("vtkMRMLModelNode", nameOfNode.c_str());
mesh->SetAndObservePolyData(poly);
mesh->CreateDefaultDisplayNodes();

```

---

<div class="post-metadata">

### Author: ![danial](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/danial/32/4888_2.png) [@danial](https://discourse.slicer.org/u/danial)
#### Post date: [October 5, 2019, 12:43pm UTC](https://discourse.slicer.org/t/create-a-vtkmrmlmodelnode-from-a-polydata/8679/3 "2019-10-05T12:43:14Z")

</div>

Thank you so much, this solution works very well.
