0
$\begingroup$

I am scripting a custom Geometry Nodes(hosted by “Cube”) with python to initiate another Geometry Node from another object(i.e. Plane). I tried this using a template searched from the internet. I didn’t bother to edit the names and other stuff but trying to add a function to test the above purpose. It can generate a new geo node under the modifier stack but it is not yet initiated. The “new” button is remained “un-pressed”. Thus, I need to add a script to “press” the “new” button as follows:

bpy.ops.node.new_geometry_node_group_assign(override, modifier="nnn")

Attached blender file as reference:

However, when I do the override on the following for assigning a new geometry nodes(equivalent to press the “NEW” button on the modifier stack for the geo node, Blender either crashed quit or remained the geo node uninitiated: code snapshot with lines number bpy.ops.node.new_geometry_node_group_assign(override, modifier="nnn")

I tried many times and tweak the scripts to avoid crash but still in vain. Can someone be kind enough to help me solve this issue? Try to use the Cube's geometry node to generate another for the object Plane node when adding "is Rendered View" the geo node created for Plane remain uninitiated but Blender sometimes crashed when adding the above script: 'new_geometry_node_group_assign(override, modifier="nnn" ' during adding the node "is Rendered View"

$\endgroup$
3
  • $\begingroup$ The .blend file contains the default cube, with Geometry Nodes that do nothing, with the node tree having the Group Input directly connected to the Group Output, and a free-floating (disconnected) "is Viewport" node. There's also a plane, a light and a camera. There's a script in the Scripting workspace that seems to introduce the "is Viewport" ("is rendered view" is the opposite?) functionality in Blender version that didn't yet support it. According to the quellenform's list that would be B2.92. $\endgroup$ Commented Sep 20, 2023 at 11:16
  • $\begingroup$ So I figure you want to create custom nodes in Python? That's the way the question should be phrased then, concentrate on what you want to achieve, not on the technicalities ( en.wikipedia.org/wiki/XY_problem ). Asking to fix bugs is off-topic to this site. $\endgroup$ Commented Sep 20, 2023 at 11:18
  • $\begingroup$ Thanks for your reply and I tried to rephrase the title and content to explicitly express I wanted to script the custom geometry node. On the other hand, you suggest it is a bug but I am not sure whether it is a bug or just my incapability to initiate a geometry node by python but it needs to be initiated from another geometry node because I need to "apply the geo node" finally. $\endgroup$
    – Patrick
    Commented Sep 20, 2023 at 11:41

1 Answer 1

0
$\begingroup$

The two errors are are bpy.ops.node.new_geometry_node_group_assign does not recognize modifier as a keyword. Another one is, using the override dictionary returns {'CANCELLED'}. To fix this, replace bpy.ops.node.new_geometry_node_group_assign(override, modifier = 'nn') with,

with bpy.context.temp_override(**override):
    bpy.ops.node.new_geometry_node_group_assign()

Changing the modifier name of the modifier can be achieved by running obj.modifiers.active_name = 'nn'.

You may want this behavior, but I don't know if you want to create new modifiers per update of the node (on creation, on new sockets, or on link). You may just do all this stuff in the init function of the node.

$\endgroup$

You must log in to answer this question.

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