# How to manually create a polyData with multi line segments in vtk.js

**URL:** https://discourse.vtk.org/t/how-to-manually-create-a-polydata-with-multi-line-segments-in-vtk-js/3636
**Category:** Web
**Created:** [June 25, 2020, 12:40am UTC](https://discourse.vtk.org/t/how-to-manually-create-a-polydata-with-multi-line-segments-in-vtk-js/3636 "2020-06-25T00:40:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![meihuisu](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/9fc348/32.png) [@meihuisu](https://discourse.vtk.org/u/meihuisu)
#### Post date: [June 25, 2020, 12:40am UTC](https://discourse.vtk.org/t/how-to-manually-create-a-polydata-with-multi-line-segments-in-vtk-js/3636/1 "2020-06-25T00:40:43Z")

</div>

I am writing a reader reading a multi-segment text file for Generic Mapping Tools.  
It contains many 3-tuples

```
const polydata = vtkPolyData.newInstance({ name: data.pieces[idx] });
      const pts = data.vset[idx];
      const cellArray = [];
      let cnt=pts.length;
      cellArray.push(cnt);
      for(let i=0; i<cnt; i++) {
        cellArray.push(i);
      }
      polydata.getLines().setData(Uint16Array.from(cellArray));
      polydata.getPoints().setData(Float32Array.from(pts), 3);
```

would appreciate a pointer to an example…

found it,  
from [How to manually create a polyData with multi line segments in vtk.js](https://discourse.vtk.org/t/how-to-manually-create-a-polydata-with-multi-line-segments-in-vtk-js/3636)

the getLines() takes an array of [total\_pt\_cnt, index of points]

---

<div class="post-metadata">

### Author: ![meihuisu](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/9fc348/32.png) [@meihuisu](https://discourse.vtk.org/u/meihuisu)
#### Post date: [June 26, 2020, 12:55am UTC](https://discourse.vtk.org/t/how-to-manually-create-a-polydata-with-multi-line-segments-in-vtk-js/3636/2 "2020-06-26T00:55:20Z")

</div>

> [@Manually Create PolyData in vtk.js](https://discourse.vtk.org/t/manually-create-polydata-in-vtk-js/885/4):
>
> One thing that could be worth adding to the vtkDataArray could be the setTuple{1,2,3,6} methods. That way you could have a similar feel. But we were also trying not to wrap any functionality that could be naturally achieved on the native JS arrays.

is the link I wanted to point to. Thanks. got my reader working.
