3
$\begingroup$

I have a mesh object created by geometry nodes - it's basically a plane divided into smaller segments. In the spreadsheet, I can see the number of faces and vertices. But when trying to access this information from Python, it appears that Python only sees the base mesh (to which the geo nodes modifier is applied). That is - Python only sees 1 face, not N faces.

Is there a way for Python to access the output of the geometry nodes modifier?

$\endgroup$
1
  • 1
    $\begingroup$ Check out the first code example here. $\endgroup$
    – scurest
    Commented Jan 31, 2023 at 0:13

1 Answer 1

5
$\begingroup$

This code prints the number of faces before and after modifiers (original data vs evaluated data):

from bpy import context as C
dg = C.evaluated_depsgraph_get()
ev = C.object.evaluated_get(dg)
print("Faces:", len(C.object.data.polygons))
print("Evaluated Faces:", len(C.object.evaluated_get(dg).data.polygons))
$\endgroup$
2
  • $\begingroup$ A further question - How do I iterate over all vertices on an evaluated face/polygon? It doesn't appear to be the same as the mesh data before modifiers are applied. $\endgroup$
    – G.H.
    Commented Jan 31, 2023 at 0:56
  • $\begingroup$ Nevermind - I figured it out. for Vert in mesh.data.polygons.vertices provides an index I can use to call on the coords in mesh.data.vertices... $\endgroup$
    – G.H.
    Commented Jan 31, 2023 at 1:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .