0
$\begingroup$

Before:

enter image description here

After:

enter image description here

Code:

import bpy, time
la = []

armature = bpy.data.objects['arma']

for obj in bpy.data.collections["edges"].all_objects:
    la.append(obj)

for id, obj in enumerate(la):
    new_name = f'edge_{id + 1}'
    if la[id].name != new_name:
        obj.name = new_name
        
if armature.mode == "EDIT":
    bone_editor = armature.data.edit_bones
    main_bone = armature.data.edit_bones['main bone']
    for obj in la:
        objPos = obj.location
        
        localNewBone = bone_editor.new(f'bone_of_{obj.name}')
        
        localNewBone.head = (0, 0, 0)
        localNewBone.tail = (0, 0, 0.125)
        
        localNewBone.translate(objPos)
        
        localNewBone.use_connect = False
        localNewBone.parent = main_bone
        
    bpy.ops.object.mode_set(mode='OBJECT')
        
        
elif armature.mode == "POSE":
    for obj in la:
        for bone in armature.data.bones:
            if bone.name == f'bone_of_{obj.name}':
                #time.sleep(0.01)
                obj.parent = armature
                obj.parent_bone = bone.name
                obj.parent_type = 'BONE'
                
    bpy.ops.object.mode_set(mode='EDIT')
$\endgroup$

0

You must log in to answer this question.

Browse other questions tagged .