1
$\begingroup$

Very noob question here, I am probably missing something and can't get my code to work properly. I want to create a new object, cube or whatever, add a Geometry nodes modifier to it and select from a drop down menu an existing, 'Fake user' group named 'Mygroup'. This last part is not working properly, I cannot get it to select that group even though if I go manually I can see it and select it normally. Most recently I tried answers from this post and modified it to correct name but id doesn't work. I am using Blender 3.31 and as I write 3.4.

My code looks like this:

import bpy

bpy.ops.mesh.primitive_cube_add(enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))

bpy.ops.object.modifier_add(type='NODES')
bpy.data.node_groups['Mygroup']
$\endgroup$
3
  • $\begingroup$ Hello, could you elaborate on what exactly doesn't work ? It throws an error ? $\endgroup$ Commented Dec 7, 2022 at 20:09
  • $\begingroup$ So just that last part, after creating an object and adding a geometry nodes modifier I cannot get it to select an existing node group from the drop down list. $\endgroup$ Commented Dec 7, 2022 at 20:51
  • $\begingroup$ It doesnt create an error, it just doesnt sellect a group $\endgroup$ Commented Dec 7, 2022 at 21:36

1 Answer 1

3
$\begingroup$

Make sure to have a Node group already in the scene.

import bpy
bpy.ops.mesh.primitive_cube_add()
bpy.context.object.modifiers.new('geometry','NODES')
bpy.context.object.modifiers['geometry'].node_group = bpy.data.node_groups['Mygroup']
$\endgroup$
1
  • $\begingroup$ That's it, solved! I get it. Thank you Muzammil. $\endgroup$ Commented Dec 8, 2022 at 7:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.