使用 python 在搅拌机中选择对象的子元素

Selecting subelements of objects in blender using python

我正在使用搅拌机,我需要将 material 应用到 comp_1_1_2_a。我已经尝试这样做但是它没有属性 "materials" 所以我需要 material 到 comp_1_1_2_a 的每个子元素。我如何使用 python 脚本 select 他们?

一个对象将其子项列表保存为 obj.children

import bpy

for obj in bpy.data.objects['comp_1_1_2_a'].children:
    if len(obj.material_slots) == 0:
        bpy.context.scene.objects.active = obj
        bpy.ops.object.material_slot_add()
    obj.material_slots[0].material = bpy.data.materials['Material']