Hello,

I am new in Python.

I am trying to find the distance between each vertex and its neighbours.

I access neighbours of each vertex with list(M.Vertices.GetVertexNeighbours(i))

However, I could not access the point coordinates of each neighbour by writing M.Vertices.GetVertexNeighbours(i[0])

Could you suggest me a way to get a list of point coordinates of each neighbour?

# Coordinate of each element in a list of list

**mimosapudica**(mimosapudica) #1

**clement**#2

Hi @mimosapudica,

`GetVertexNeighbours`

returns an array of vertex indices not Points. To access the vertex point and measure the distance you would have to access one neighbour in the loop at line 17 like this:

`neighbour_vertex_pt = M.Vertices[j]`

then get the distance to the vertex you store at line 10 like this:

`distance = V.DistanceTo(neighbour_vertex_pt)`

_

c.

**mimosapudica**(mimosapudica) #3

Thanks, Clement.

I understood that neighbour_vertex_pt = M.Vertices[j] gives each neighbour of a node in the list.

when I use DistanceTo, I get this error.

Runtime error (MissingMemberException): ‘PlanktonVertex’ object has no attribute ‘DistanceTo’

I also tried to use this line below but could not get the distance between each node with its neighbours but I got the same error

distances= neighbour_vertex_pt.pos-V.pos

Here is the code:

import rhinoscriptsyntax as rs

import Rhino.Geometry as rg

import Rhino

V_count = M.Vertices.Count # number of all vertices

V_list=[]

VN_list=[]

for i in range(V_count):

V= M.Vertices[i]

#N=M.Vertices.GetVertexNeighbours(i)

point=(V.X,V.Y,V.Z)

nodes=rs.AddPoint(point)

V_list.append(nodes)

```
VN_idx = list(M.Vertices.GetVertexNeighbours(i))
for j in VN_idx:
number_of_Neighbours=VN_idx.Count
neighbour_vertex_pt = M.Vertices[j]
distance = distances= neighbour_vertex_pt.pos-V.pos![IMG_7827%20(1)|612x500](upload://vBpYn2CcJYkCTFziyVrPGf0lUWn.jpg)
```

**qythium**(qythium) #4

Try converting your PlanktonMesh into a regular Rhinocommon Mesh before plugging it into the Python component, and make sure the type hint on the input is set to Mesh or None.

Also, if you are working directly with Rhino.Geometry types, try not to mix with rhinoscriptsyntax methods like `rs.AddPoint`

, or there will be unnecessary trouble converting back and forth from Guids.

**clement**#5

is there a reason you use the Plankton mesh as input or do you need the halfedge structure at all ?

If not, i would suggest to use the regular `Mesh` component as input to your Python component, then you can omit using `GetVertexNeighbours`

and use GetConnectedVertices method instead to get the neighbours.

If you need the Plankton mesh as input, you can try to get a `Point3d`

from the Plankton vertex, then `DistanceTo`

works:

```
import Rhino.Geometry as rg
import Rhino
for i, p_vertex in enumerate(M.Vertices):
# get 3d point from plankton vertex
v_pt = rg.Point3d(p_vertex.X, p_vertex.Y, p_vertex.Z)
# get neighbour indices
neighbour_indices = M.Vertices.GetVertexNeighbours(i)
print "Vertex {} has {} neighbours".format(i, neighbour_indices.Count)
for n in neighbour_indices:
# get 3d point from neighbour plankton vertex
n_pt = rg.Point3d(M.Vertices[n].X, M.Vertices[n].Y, M.Vertices[n].Z)
# mesasure distance
distance = v_pt.DistanceTo(n_pt)
print "Distance to neighbour with index {} = {}".format(n, distance)
```

_

c.

**mimosapudica**(mimosapudica) #6

Thank you @clement I solved neighbouring problem.

I will try to deform the mesh and relax.

I am trying to displace the vertex of mesh with iteration. When I click the test in gh python each time, it does not reset the mesh. I try to find copy mesh in gh python. It did not work.

How can we make a complete copy of mesh inside gh python?

How can I reset the mesh?

190525_Mesh_reset.gh (14.2 KB)

**clement**#7

Hi @mimosapudica, i am getting an error if i try to open your file, `MeshFromPoints`

is missing and i was not able to install it.

Have you tried something like `mycopy = mesh.Duplicate()`

?

_

c.

**mimosapudica**(mimosapudica) #8

It did not work. I am sending you the file .3dm and .gh again.190525_Mesh_reset_problem.3dm (1.5 MB)

190525_Mesh_reset.gh (14.3 KB)