0
$\begingroup$

I have defined a custom EnumProperty for objects. I want to be able to change the property for all selected objects simultaneously. I tried this:

def set_collider(self, context):
    selected_objs = context.selected_objects
    collider = context.active_object.ECollider
    for obj in selected_objs:
        if obj != context.active_object:
            obj.ECollider = collider

bpy.types.Object.ECollider = EnumProperty(
    items=[('NC', 'None', ''), ('BC', 'Box Collider', ''), ('SC', 'Sphere Collider', '' ), ('CC', 'Capsule Collider', '')], name="Collider", update=set_collider
)

but for some reason blender crashes every time I select multiple objects and change the ECollider property through the UI panel.
Of course I can always right click on the property and select Copy to Selected but it would be more convenient if I could change the property for all selected objects at once.

$\endgroup$
0
$\begingroup$

Instead of accessing the ECollider like this: object.ECollider now I access it this way: object['ECollider'] and everything works fine. Full code modification:

def set_collider(self, context):
    selected_objs = context.selected_objects
    collider = context.active_object['ECollider']
    for obj in selected_objs:
        if obj != context.active_object:
            obj['ECollider'] = collider

bpy.types.Object.ECollider = EnumProperty(
    items=[('NC', 'None', ''), ('BC', 'Box Collider', ''), ('SC', 'Sphere Collider', '' ), ('CC', 'Capsule Collider', '')], name="Collider", update=set_collider
)
$\endgroup$

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.