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):
        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]

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:
    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()):
  • $\begingroup$ instead of your re match you could use the object's type field. Collecting all curves [object for object in bpy.data.objects if object.type == 'CURVE'] for example $\endgroup$ Jan 18 at 18:51

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))


#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
            curve.select = False

if (bpy.ops.object.join.poll()):
  • $\begingroup$ I think you solution is practically same as mine above and causes me same Error: EXCEPTION_ACCESS_VIOLATION.. problem is elsewhere I think. Can't figure where. $\endgroup$
    – Destrosvet
    Sep 3 '18 at 15:22
  • $\begingroup$ yes it is more or less the same, I am not getting any related error, does this script is working although ? Can you pass the console error you get ? (looks like an exception) $\endgroup$
    – cnisidis
    Sep 3 '18 at 16:57
  • 1
    $\begingroup$ Iterate over scene.objects rather than all the curves in file (bpy.data.objects), which may or may not be linked to scene. Often safer with bound vectors to copy them, so they are no longer assoc with object (prob not case here, possibly case in question) color = ob.blah.blah.diffuse_color.copy() $\endgroup$
    – batFINGER
    Oct 14 '18 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.