<div dir="auto">Blender python to attach an object to armature and bone.</div><div dir="auto"><br></div><div dir="auto">import bpy</div><div dir="auto"><br></div><div dir="auto"># Get the object and armature</div><div dir="auto">obj = bpy.context.object</div><div dir="auto">armature = bpy.data.armatures["ArmatureName"]</div><div dir="auto"># Get the bone to parent to</div><div dir="auto">bone = armature.bones["BoneName"]</div><div dir="auto"># Set the parent</div><div dir="auto">obj.parent = armature</div><div dir="auto">obj.parent_type = 'BONE'</div><div dir="auto">obj.parent_bone = <a href="http://bone.name">bone.name</a>
</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">Note that the object’s parent is the armature, not the bone.</div><div dir="auto"><br></div><div dir="auto">It’s possible I used bone instead of <a href="http://bone.name">bone.name</a>.</div><div dir="auto"><br></div><div dir="auto">The XML nodes are traversed in order, typically.</div><div dir="auto"><br></div><div dir="auto">No one says if it’s possible to set child objects of objects to  the armature as a parent . I don’t know if there’s a hierarchy of objects under the armature or not.  Typically, I’m traversing a hierarchy of children, and I will have to know if the whether the parent is a bone or not.  If the parent is a bone, then i do the above.</div><div dir="auto"><br></div><div dir="auto">Should I attach objects of nodes below obj’s XML node to the armature parent or obj?</div><div dir="auto"><br></div><div dir="auto">How do I tell if I should attach to armature or obj for grandchildren?</div><div dir="auto"><br></div><div dir="auto">Realize that i will be attaching empty objects, there’s no equivalent for site or segment in blender.  This will mean that I will probably have a hierarchy of bones and a hierarchy of objects (sites, segments, transforms (as empty objects) and geometry).  I am not prepared for this algorithm on export, where a bone hierarchy is “separate” from the object hierarchy with no known way of getting bone children, except other bones.  That’s a huge problem I will have. To test for bone parents for each object (say under armature) and insert a joint above the armature children.  Then, I won’t even know if they are Transforms, HAnimSites or HAnimSegments, because there’s only adhoc ways of determining x3d node type from empty objects (naming, custom properties).  If it’s a foreign import, how do I render it’s object hierarchy under armature as X3D?  I can’t put Transforms under HAnimJoints!</div><div dir="auto"><br></div><div dir="auto">If I’m adding joint objects, should I add both bones and objects?</div><div dir="auto"><br></div><div dir="auto">Realize none if this armature or bone stuff was in the exporter before and I’ve been adding it in addition to animations that need to work.</div><div dir="auto"><br></div><div dir="auto">I think the best I can hope for is a flat bone hierarchy.  Maybe that’s what I’ll do.</div><div dir="auto"><br></div><div dir="auto">John </div>