Join curves with Python by color I'd like to group curves by color, so I'm try to join them together. I used an override from this solution. Everything works splendid inside Blender but in my external program I have 


  AttributeError: 'ID' object has no attribute 'data'


This is function:

def curvegroup():
for crvobj in bpy.data.objects:
    if re.match(r'^curve', crvobj.data.name):
        crvs = []
        color = crvobj.active_material.diffuse_color
        for crvobjcol in bpy.data.objects:
            if re.match(r'^curve', crvobjcol.data.name):
                if (crvobjcol.active_material.diffuse_color == color):
                    crvs.append(crvobjcol)
        ctx = bpy.context.copy()
        ctx['active_object'] = crvs[0]
        ctx['selected_objects'] = crvs
        ctx['selected_editable_bases'] = [scene.object_bases[crv.name] for crv in crvs]
        bpy.ops.object.join(ctx)


I am not sure that I understand scene.object_bases so I really don't know why ID object is there and what cause this error. 

Another method causes Error: EXCEPTION_ACCESS_VIOLATION

def curvegroup02():
for crvobj in bpy.context.scene.objects:
    bpy.ops.object.select_all(action='DESELECT')
    if re.match(r'^Curve', crvobj.name):
        scene.objects.active = crvobj
        color = crvobj.active_material.diffuse_color
        for crvobjcol in bpy.context.scene.objects:
            if re.match(r'^Curve', crvobjcol.data.name):
                if (crvobjcol.active_material.diffuse_color == color):
                    crvobjcol.select = True

        for selected in bpy.context.selected_objects:
            if selected.type == 'CURVE':
                if (bpy.ops.object.join.poll()):
                    bpy.ops.object.join()
I hope that this script may help you, just pick the curve that has the "guide" color and run the script.

import bpy
import mathutils

#set custom color

#color = mathutils.Color((1,0,0))

#or

#use active's object diffuse color

color = bpy.context.active_object.active_material.diffuse_color

for obj in bpy.data.objects:
    if obj.type == 'CURVE':
        curve = obj
        if curve.active_material.diffuse_color == color:
            curve.select = True
        else:
            curve.select = False


if (bpy.ops.object.join.poll()):
    bpy.ops.object.join()