0
$\begingroup$

In blender 5.0 beta there is the new array modifier. ( in the background it is actually a "geometry node group" )

The modifier can be added and updated via python with:

bpy.ops.object.modifier_add_node_group(asset_library_type='ESSENTIALS', 
                                        asset_library_identifier="", 
                                        relative_asset_identifier="nodes/geometry_nodes_essentials.blend/NodeTree/Array", 
                                        use_selected_objects=False)
bpy.context.object.modifiers["Array"]["Socket_5"] = 6 # set the count
bpy.context.object.modifiers["Array"].node_group.interface_update(bpy.context) # update UI and 3D Viewer

Does anyone know how to create this NodesModifier without using bpy.ops ?

Thanks

$\endgroup$
0

1 Answer 1

1
$\begingroup$

https://projects.blender.org/blender/blender/issues/117399

import bpy
import os

object = bpy.context.object

node_group_name = 'Array'

node_group = bpy.data.node_groups.get(node_group_name)
if not node_group:
    path = os.path.join(
        os.path.dirname(bpy.app.binary_path),
        f'{bpy.app.version[0]}.{bpy.app.version[1]}',
        'datafiles', 'assets', 'nodes', 'geometry_nodes_essentials.blend'
    )
    with bpy.data.libraries.load(path) as (data_from, data_to):
        data_to.node_groups = [node_group_name]

    node_group = data_to.node_groups[0]

modifier: bpy.types.NodesModifier = object.modifiers.new(name = node_group_name, type = 'NODES')
modifier.node_group = node_group
$\endgroup$

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.