0
$\begingroup$

I'm trying to reuse a code provided in an answer here: Python Geometry Node Trees

import bpy

bpy.ops.curve.primitive_bezier_curve_add()
bpy.ops.object.modifier_add(type='NODES')

curve = bpy.context.active_object
node_group = curve.modifiers[-1].node_group
nodes = node_group.node

group_in = nodes.get('Group Input')
group_out = nodes.get('Group Output')

new_node = nodes.new('GeometryNodeMeshToPoints')

node_group.links.new(group_in.outputs['Geometry'], new_node.inputs['Mesh'])
node_group.links.new(new_node.outputs['Points'], group_out.inputs['Geometry'])

but Blender returns something like this (regarding the line with "nodes = node_group.node"):

Python: Traceback (most recent call last):
  File "\Text", line 8, in <module>
AttributeError: 'NoneType' object has no attribute 'node'

What should I do to fix it?

$\endgroup$
5
  • $\begingroup$ This means the node_group variable is None. Which in turn means that the curve modifier has no node group set. If you create a raw modifier like this it will not have any nodes assigned to it by default, you need to either set these manually or assign them in the script, like curve.modifiers[-1].node_group = bpy.data.node_groups['SomeGroupYouMade'] $\endgroup$
    – user436
    Commented Jun 22, 2022 at 17:25
  • $\begingroup$ @lukas_t How should I use this script? If I insert it before "nodes = node_group.node", it returns with: Python: Traceback (most recent call last): File "\Text", line 8, in <module> KeyError: 'bpy_prop_collection[key]: key "SomeGroupYouMade" not found' $\endgroup$
    – ForceX
    Commented Jun 22, 2022 at 17:37
  • $\begingroup$ @ForceX you're supposed to replace the string SomeGroupYouMade with the name of the group that you created. $\endgroup$ Commented Jun 22, 2022 at 17:47
  • $\begingroup$ @MartyFouts But is this already in the code provided above or do I have to write something that would create such a group? If so, how do I do it? I'm very sorry, I've started scripting very recently. $\endgroup$
    – ForceX
    Commented Jun 22, 2022 at 17:55
  • $\begingroup$ FWIW I modified the answer to add a new node group blender.stackexchange.com/a/249779/86891 $\endgroup$
    – Gorgious
    Commented Jun 23, 2022 at 5:34

1 Answer 1

3
$\begingroup$

In 3.1 it is simple.

Change node to nodes here:

nodes = node_group.nodes

In 3.2 you shold manually create a node_group according to this change

$\endgroup$
6
  • $\begingroup$ It still returns with the same AttributeError $\endgroup$
    – ForceX
    Commented Jun 22, 2022 at 18:07
  • $\begingroup$ Hm, are you sure? What blender version do you have? $\endgroup$
    – Crantisz
    Commented Jun 22, 2022 at 18:19
  • $\begingroup$ The version is 3.2.0 This is how it looks: i.postimg.cc/QtYyJ58Z/b320.png $\endgroup$
    – ForceX
    Commented Jun 22, 2022 at 18:25
  • $\begingroup$ Yep, works fine in 3.1 and has an error in 3.2 $\endgroup$
    – Crantisz
    Commented Jun 22, 2022 at 18:34
  • $\begingroup$ Oh yeah, I switched to 3.1 and it worked. Thank you! $\endgroup$
    – ForceX
    Commented Jun 22, 2022 at 19:03

You must log in to answer this question.

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