# Can someone point me to an example of pulling vertices from faces obtained from AssociationDef?

**URL:** https://discourse.kitware.com/t/can-someone-point-me-to-an-example-of-pulling-vertices-from-faces-obtained-from-associationdef/909
**Category:** Using SMTK
**Created:** [October 4, 2022, 4:29pm UTC](https://discourse.kitware.com/t/can-someone-point-me-to-an-example-of-pulling-vertices-from-faces-obtained-from-associationdef/909 "2022-10-04T16:29:18Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![dcthomp](https://discourse.kitware.com/user_avatar/discourse.kitware.com/dcthomp/32/10_2.png) [@dcthomp](https://discourse.kitware.com/u/dcthomp)
#### Post date: [October 11, 2022, 6:57pm UTC](https://discourse.kitware.com/t/can-someone-point-me-to-an-example-of-pulling-vertices-from-faces-obtained-from-associationdef/909/5 "2022-10-11T18:57:54Z")

</div>

@RHMoore Sorry this slipped off my radar.

Once you [have a model entity](https://discourse.kitware.com/t/using-the-python-interpreter-included-with-cmb-and-aevacmb/620) of interest selected in python (i.e., the SMTK face, like `face..bcc2`), you can get to the VTK data like so:

```python
from vtkmodules.util.numpy_support import vtk_to_numpy as vton
# Fetch the session object from the resource that owns the face of interest:
session = face.resource().session()
# Fetch the VTK object from the session by passing the UUID of the face:
faceData = session.findStorage(face.id())
# The VTK object may be vtkPolyData, vtkUnstructuredGrid, or vtkImageData
# and in any case should have global cell and point IDs.
cellIds = vton(faceData.GetCellData().GetGlobalIds())
nodeIds = vton(faceData.GetPointData().GetGlobalIds())
# If you want the locations of points in space, you can get those, too:
nodeCoords = vton(faceData.GetPoints().GetData())
# Finally, you many need connectivity information about which offsets into the
# nodeIds and nodeCoords a given cell references. This is different for
# vtkPolyData vs vtkUnstructuredGrid vs vtkImageData. For polydata, if you
# are interested in surface elements (triangles, quads), then
off = vton(faceData.GetPolys().GetOffsetsArray())
conn = vton(faceData.GetPolys().GetConnectivityArray())
# The "off" array is of length N+1, where N is the number of cells
# and each value an offset into the connectivity array "conn".
# The "conn" array holds offsets into all the point arrays (nodeIds, nodeCoords).

```

So, if you are interested in the nodes of cell 10, you can see how many nodes it has with `numNodes = off[11] - off[10]` and then get global point IDs

```python
pointIdsOfCell10 = [nodeIds[ii] for ii in conn[off[10]:off[10+1]]]

```

Similarly, for point locations

```python
pointsOfCell10 = [nodeCoords[ii,:] for ii in conn[off[10]:off[10+1]]]

```

**NB** : For the benefit of others, this reading this later, these instructions work for sessions based on `smtk::model::Resource` such as `smtk::session::vtk` or `smtk::session::aeva`. Other sessions such as opencascade don’t have VTK data backing model entities.

---

_[View the full topic](https://discourse.kitware.com/t/can-someone-point-me-to-an-example-of-pulling-vertices-from-faces-obtained-from-associationdef/909)._
