2
$\begingroup$

Say you generate some random points using Geometry Nodes, how can you get all those point coordinates using the python api?

The only hint I have is that the point coords are located under Point Cloud in the Spreadsheet Editor.

Basically, I want to use those coordinates for scripting other stuff I can't do with Geometry Nodes yet.

enter image description here

$\endgroup$

1 Answer 1

1
$\begingroup$

This is a workaround and I hope there is (or will eventually be) an easier way to access point cloud data in the API.

enter image description here

Instead of instancing points, create a new object, eg. a cube, go into edit mode, select everything and right click > Merge Vertices > At Center. That way you have an object with a single vertex at world origin.

In your GN tree add a Point Instance node and choose your single vertex object.

enter image description here

In theory we should be able to access the vertices' geometry but for now the geometry is not "real". We need to trick the modifier into creating real geometry. There are multiple nodes for which it will work. I plugged a default and blank Attribute Math node before the modifier output.

enter image description here

Then, we need to access the evaluated mesh, after the GN modifier has been applied. For that we can use the context dependency graph.

import bpy

depsgraph = bpy.context.evaluated_depsgraph_get()
obj = bpy.context.active_object.evaluated_get(depsgraph)

print([v.co for v in obj.data.vertices])

Result :

enter image description here

$\endgroup$
2
  • $\begingroup$ i love workaround if they work!! Great job! $\endgroup$
    – Chris
    Jun 10, 2021 at 7:18
  • 1
    $\begingroup$ Yeah, hopefully they simplify this so vertex instancing isn't needed, but for now it works so thank you! $\endgroup$ Jun 10, 2021 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.