# Not getting poly data

**URL:** <https://discourse.slicer.org/t/not-getting-poly-data/2775>\
**Category:** Development\
**Created:** [May 8, 2018, 1:38pm UTC](https://discourse.slicer.org/t/not-getting-poly-data/2775 "2018-05-08T13:38:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anandmulay3](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anandmulay3](https://discourse.slicer.org/u/anandmulay3)\
**Post date:** [May 8, 2018, 1:38pm UTC](https://discourse.slicer.org/t/not-getting-poly-data/2775/1 "2018-05-08T13:38:43Z")

</div>

```
[success, loadedVolumeNode] = slicer.util.loadVolume('\Sft.nrrd', returnNode=True)
#Segmentation
masterVolumeNode = getNode('Sft')

# Create segmentation
segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
segmentationNode.CreateDefaultDisplayNodes() # only needed for display
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode)
addedSegmentID = segmentationNode.GetSegmentation().AddEmptySegment("bone")

# Create segment editor to get access to effects
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
segmentEditorNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentEditorNode")
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
segmentEditorWidget.setSegmentationNode(segmentationNode)
segmentEditorWidget.setMasterVolumeNode(masterVolumeNode)

# Thresholding
segmentEditorWidget.setActiveEffectByName("Threshold")
effect = segmentEditorWidget.activeEffect()
effect.setParameter("MinimumThreshold","300")
effect.setParameter("MaximumThreshold","5695")
effect.self().onApply()

# Smoothing
segmentEditorWidget.setActiveEffectByName("Smoothing")
effect = segmentEditorWidget.activeEffect()
effect.setParameter("SmoothingMethod", "MEDIAN")
effect.setParameter("KernelSizeMm", 3)
effect.self().onApply()

modelNode = getNode('Sft') 
points = arrayFromModelPoints(modelNode)

```

please check above code everything works fine except last line .  
Traceback:  
‘MRMLCorePython.vtkMRMLScalarVolumeNode’ object has no attribute ‘GetPolyData’

do i need any additional code, so that i can get polydata from my node or from these segmentation process.

---

<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:** [May 9, 2018, 3:52am UTC](https://discourse.slicer.org/t/not-getting-poly-data/2775/2 "2018-05-09T03:52:25Z")

</div>

> [@anandmulay3](#):
>
> modelNode = getNode(‘Sft’)

This method will return your input volume node, the same way as this method call returns your input volume node at the beginning of your script. You can get surface mesh from your segmentation as shown in this example: [This example demonstrates how to extract skin surface from an MRI image using thresholding and smoothing effect of Segment Editor · GitHub](https://gist.github.com/lassoan/1673b25d8e7913cbc245b4f09ed853f9#file-extractskin-py-L37-L41)

---

<div class="post-metadata">

**Author:** ![anandmulay3](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anandmulay3](https://discourse.slicer.org/u/anandmulay3)\
**Post date:** [May 9, 2018, 2:03pm UTC](https://discourse.slicer.org/t/not-getting-poly-data/2775/3 "2018-05-09T14:03:20Z")

</div>

using above method to create surfacemesh i’m still not able to get polydata  
i have tried setting `modelNode = getNode(sementID)`

still am i missing any code?

---

<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:** [May 9, 2018, 3:07pm UTC](https://discourse.slicer.org/t/not-getting-poly-data/2775/4 "2018-05-09T15:07:06Z")

</div>

`getNode` expects a node name or node ID. Passing a segment ID (an internal ID within a segmentation node) will not work. Follow the example that I referenced above more closely. It should be something like this:

```
segmentationNode.CreateClosedSurfaceRepresentation()
surfaceMesh = segmentationNode.GetClosedSurfaceRepresentation(addedSegmentID)
```

---

<div class="post-metadata">

**Author:** ![anandmulay3](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anandmulay3](https://discourse.slicer.org/u/anandmulay3)\
**Post date:** [May 10, 2018, 6:52am UTC](https://discourse.slicer.org/t/not-getting-poly-data/2775/5 "2018-05-10T06:52:33Z")

</div>

yeah, i did the same thing and then i tried to getNode like this

```
modelNode = getNode(addedSegmentID)
    Traceback (most recent call last):
      File "<console>", line 1, in <module>
      File "C:\Program Files\Slicer 4.9.0-2018-05-07\bin\Python\slicer\util.py", line 631, in getNode
        raise MRMLNodeNotFoundException("could not find nodes in the scene by name or id '%s'" % (pattern if (type(pattern) == str) else ""))
    MRMLNodeNotFoundException: could not find nodes in the scene by name or id 'bone'

```

and this error comes up , in data still i cant find out the mode hierarchy;only my volume node under that segmentation and a single segment…

---

<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:** [May 10, 2018, 2:57pm UTC](https://discourse.slicer.org/t/not-getting-poly-data/2775/6 "2018-05-10T14:57:55Z")

</div>

> [@anandmulay3](#):
>
> modelNode = getNode(addedSegmentID)

This should return an error and it does, so everything works as expected. If you need a vtkPolyData of a segment, then please see my post above that shows how `surfaceMesh` variable is set.
