0
$\begingroup$

I got a simple Geometry Nodes setup that takes an existing vertex group and does stuff with it. I'd like to automatically feed it the active vertex group data.

A scripted function returning bpy.data.objects['Cube'].vertex_groups.active doesn't work because this doesn't seem to return data structured in the way a input field expects, and I'm not sure how the named attributes are structured to try to recreate it.

Alternatively, if I could find a way to assign a drive to a string input I'd be able to retrieve bpy.data.objects['Cube'].vertex_groups.active.name to then feed it to a Named Attribute node and access the vertex group data. The closest would be using the value input in a Value to String node, but that assumes all VGroups have numbers for names, which isn't the case.

$\endgroup$

1 Answer 1

1
$\begingroup$

You could use an app handler:

import bpy


def active_vertex_group_handler(scene):
    o = bpy.context.object
    o.modifiers['GeometryNodes']['Input_2'] = o.vertex_groups.active.name

bpy.app.handlers.depsgraph_update_post.append(active_vertex_group_handler)

Mind the input name - yours might be different. And you probably want to do some checks if the active object is the right type.

$\endgroup$
1
  • $\begingroup$ Clever and very simple, works like charm! To people stumbling on this question that missed how this answer it, you need to assign the driver to a dummy field, replacing the input with the string input you're modifying (which won't be the actual input where this driver is because you can't directly drive string inputs). You'll be "driving" it from inside the function instead. $\endgroup$
    – Rhaenys
    Commented Feb 15, 2023 at 17:16

You must log in to answer this question.

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