# Delete/Modify a cell in a UnstructuredGrid

**URL:** https://discourse.vtk.org/t/delete-modify-a-cell-in-a-unstructuredgrid/6772
**Category:** Support
**Created:** [October 7, 2021, 2:18am UTC](https://discourse.vtk.org/t/delete-modify-a-cell-in-a-unstructuredgrid/6772 "2021-10-07T02:18:35Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Drew](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@Drew](https://discourse.vtk.org/u/Drew)
#### Post date: [October 7, 2021, 2:18am UTC](https://discourse.vtk.org/t/delete-modify-a-cell-in-a-unstructuredgrid/6772/1 "2021-10-07T02:18:35Z")

</div>

I have an UnstructuredGrid that consists of a collection of square cells. Given an id of a particular cell I would like to either (assume that the ids for the points defining this cell are p\_0,p\_1,p\_2,p\_3)

a) delete that cell and replace it with a new triangular cell defined by p\_0,p\_1,p\_2; or  
b) modify the cell such that new cell is triangular defined by p\_0,p\_1,p\_2

If I was dealing with a PolyData object then I believe that I can delete a cell as follows

```auto
poly_data.BuildLinks()
poly_data.DeleteCell(id)
poly_data.RemoveDeletedCells()

```

and then simply add in a new cell with the appropriate properties. But how do I do this with an UnstructuredGrid? An answer using C++ or Python would be great.

---

<div class="post-metadata">

### Author: ![Jacques.chen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@Jacques.chen](https://discourse.vtk.org/u/Jacques.chen)
#### Post date: [April 2, 2022, 4:39pm UTC](https://discourse.vtk.org/t/delete-modify-a-cell-in-a-unstructuredgrid/6772/2 "2022-04-02T16:39:23Z")

</div>

hello ,did you solved you problem? I have same problem

---

<div class="post-metadata">

### Author: ![andreasbuykx](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreasbuykx/32/8137_2.png) [@andreasbuykx](https://discourse.vtk.org/u/andreasbuykx)
#### Post date: [April 4, 2022, 8:35am UTC](https://discourse.vtk.org/t/delete-modify-a-cell-in-a-unstructuredgrid/6772/3 "2022-04-04T08:35:40Z")

</div>

I got curious and took a look at vtkUnstructuredGridBase:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/0/0c278a0d49c1d01ce95173d15cd959d935c74be9.png)  
Does this help?

---

<div class="post-metadata">

### Author: ![Jacques.chen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@Jacques.chen](https://discourse.vtk.org/u/Jacques.chen)
#### Post date: [April 5, 2022, 5:39am UTC](https://discourse.vtk.org/t/delete-modify-a-cell-in-a-unstructuredgrid/6772/4 "2022-04-05T05:39:48Z")

</div>

Yes，it is wored. Do you know how to replace the cell to a empty cell?

---

<div class="post-metadata">

### Author: ![andreasbuykx](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreasbuykx/32/8137_2.png) [@andreasbuykx](https://discourse.vtk.org/u/andreasbuykx)
#### Post date: [April 5, 2022, 6:24am UTC](https://discourse.vtk.org/t/delete-modify-a-cell-in-a-unstructuredgrid/6772/5 "2022-04-05T06:24:17Z")

</div>

Have you tried VTK\_EMPTY\_CELL?

---

<div class="post-metadata">

### Author: ![Jacques.chen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@Jacques.chen](https://discourse.vtk.org/u/Jacques.chen)
#### Post date: [April 7, 2022, 4:09pm UTC](https://discourse.vtk.org/t/delete-modify-a-cell-in-a-unstructuredgrid/6772/6 "2022-04-07T16:09:21Z")

</div>

I had tried to replace cell to a VTK\_EMPTY\_CELL, but not success. have you any example?

---

<div class="post-metadata">

### Author: ![rexthor](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rexthor/32/6481_2.png) [@rexthor](https://discourse.vtk.org/u/rexthor)
#### Post date: [October 18, 2023, 7:04pm UTC](https://discourse.vtk.org/t/delete-modify-a-cell-in-a-unstructuredgrid/6772/7 "2023-10-18T19:04:31Z")

</div>

I know that this digging up an old question, but I did something similar, and I had to replace the cell array of the unstructured grid to do it. The rough idea is [here](https://discourse.vtk.org/t/can-i-avoid-adding-duplicate-cells-to-a-vtkpolydata/12483/2).
