I am trying to generate roads from curves that i have placed in the scene. I have three curves and a road mesh that I apply a curve and array modifier to through python. I also set the values of the modifiers through python.
In python I loop through all objects in the scene, and for each curve I duplicate the main road mesh and apply modifiers with the new curve as the target.
My problem is that for each road it duplicates the road by an amount of 2 * the previously duplicated amount. So for the first curve it makes one road, for the second curve 2 roads, and 4 roads for the 3rd curve so on so forth.
I am fairly new to blender programming, so I am certain i'm missing something logical, but I can't figure out what.
Finally here's the code for the operator:
def execute(self, context):
objects = bpy.context.scene.objects
road = bpy.data.objects["Road"]
for obj in objects:
if obj.type == "CURVE":
road = bpy.data.objects["Road"]
bpy.data.objects['Road'].select_set(True)
newroad = road.copy()
bpy.context.collection.objects.link(newroad)
bpy.ops.object.modifier_add(type='ARRAY')
bpy.ops.object.modifier_add(type='CURVE')
arrmod = bpy.context.object.modifiers["Array"]
curvemod = bpy.context.object.modifiers["Curve"]
arrmod.fit_type = 'FIT_CURVE'
arrmod.curve = bpy.data.objects[obj.name]
curvemod.object = bpy.data.objects[obj.name]
return{'FINISHED'}
Thanks!