Here's a VEX function to get primitive neighbours either by shared points or by shared edges. Use the type function input for the two different methods (0 points, 1 edges);
function int []primneighbours (int geometry; int prim; int type) { int primPts[] = primpoints(geometry, prim); int nearPrims[]; int sharedPrims[]; // Find primitives attached to the input primitive-points foreach(int num; int pt; primPts) { int ptPrims[] = pointprims(geometry, pt); foreach(int num1; int ptPrim; ptPrims) { int used = 0; foreach(int num2; int usedPrim; nearPrims) { if(usedPrim == ptPrim) { used = 1; } } if(used == 0) { append(nearPrims, ptPrim); } } } // Find primitives sharing the two or more points with the input primitive foreach(int num3; int nearPrim; nearPrims) { int tempPrimPts[] = primpoints(geometry, nearPrim); int similarPts = 0; foreach(int num4; int tempPrimPt; tempPrimPts) { foreach(int num5; int primPt; primPts) { if(tempPrimPt == primPt) { similarPts++; } } } if(similarPts > 1) { append(sharedPrims, nearPrim); } } // Return based on input type if(type > 0) { return sharedPrims; } else { return nearPrims; } }
Use the function like this (outside the function itself):
int neigh[] = primneighbours(0, @primnum, 1);
Grouping neighbours example:
int neigh[] = primneighbours(0, 70, 1); foreach(int num; int prim; neigh) { setprimgroup(0, "nearPrims", prim, 1, "set"); }
Enjoy!