Assigning Array and Curve for a large number of curves I have a very large number of curves (OpenStreetMap data imported as curves) on which I wish to array objects (streetlights).
Since there are thousands of curve objects, duplicating my streetlight object and then manually adding an array and curve modifier and point them to the right curve is a slow if not impossible process when there is this many curve objects.

The best solution I can think of is a script, however I am not familiar with the process. I've only gone as far as making the script add an array modifier.

The imported curves are all numbered as Road0, Road1, Road2, Road3, etc

Here is my script so far

import bpy

bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(-0, 0, 0), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})
bpy.ops.object.modifier_add(type='ARRAY')
bpy.context.object.modifiers["Array"].fit_type = 'FIT_CURVE'
bpy.context.object.modifiers["Array"].relative_offset_displace[0] = 50
bpy.context.object.modifiers["Array"].curve = bpy.data.objects["RoadTertartiary0"]


I basically need a way to make that last 0 increment every time I run the script

Sample Blend file:


Any help is appreciated.
Thank you lemon, your script is very useful, it is just what I need from a year ago.
I edited the script (names for a more generic work and not linked to the lamp), Mainpath for curves and Mainclone name for object. I changed the type of displacement to Constant Offset.
import bpy
import bmesh

# Scripting: lemon
# https://blender.stackexchange.com/users/19156/lemon
# Aug 15 '19 at 12:37
# get an existing collection or create it if it does not exist
# if created, the collection is added to the scene main collection
def get_or_create_collection( scene, collection_name ):
    collection = bpy.data.collections.get( collection_name )
    if collection is None:
        collection = bpy.data.collections.new( collection_name )
        scene.collection.children.link( collection )
    return collection

# duplicate an object and link it to a collection
# copy_data allow to know if the objects will share their data or not (are dupli or not)
def duplicate( obj, collection, copy_data ):
    new_obj = obj.copy()
    if copy_data:
        new_obj.data = obj.data.copy()
    collection.objects.link( new_obj )
    return new_obj

# get the scene
scene = bpy.context.scene

# get the base main clone
base_Mainclone = bpy.data.objects[&quot;Mainclone&quot;]

# names of the collections
mainpath_collection_name = &quot;Mainpath&quot;
clones_collection_name = &quot;Created_clones&quot;

# get the source collection
mainpath_collection = bpy.data.collections.get( mainpath_collection_name )

if mainpath_collection is None or base_Mainclone is None:
    print( &quot;will not work&quot; )
else:
# get the destination collection
clones_collection = get_or_create_collection( scene, clones_collection_name )

for mainpath in [r for r in mainpath_collection.objects if r.type == 'CURVE']:
    # Duplicate the base main clone (True =&gt; not linked)
    Mainclone = duplicate( base_Mainclone, clones_collection, True )
    # Set the lamp at the road location so that curve can work
    Mainclone.location = mainpath.location
    # Add the array modifier
    array_modifier = Mainclone.modifiers.new( &quot;array&quot;, 'ARRAY' )
    array_modifier.fit_type = 'FIT_CURVE'
    array_modifier.use_relative_offset = False
    array_modifier.use_constant_offset = True
    array_modifier.constant_offset_displace[0] = 10
    array_modifier.curve = mainpath
    # Add the curve modifier
    curve_modifier = Mainclone.modifiers.new( &quot;curve&quot;, 'CURVE' )
    curve_modifier.object = mainpath

print( 'done' )