Armature - Mesh Association?

Hi All,

I’ve been through the API and can’t find anything on this.

I have an armature with two meshes parented to it.

Let’s say I have the armature selected and I want to use Python to find out if any meshes are attached to it. If there are, is it possible to get a list of objects?

Or do I have to iterate through all the objects in the scene to see if they reference the armature?

In the past, I’ve run though the list of Objects and looked for ones that have an “Armature” modifier with the armature that I’m testing for. You might get away with just checking for Object that are parented to your source armature.

Never mind. I wasn’t going high enough in the inheritance structure.

Oops! Didn’t see your reply before posting that last message.

Thanks for jumping in. As it turns out, all objects access their child objects using .children, so the problem is solved.

Here’s a sample:

list(bpy.data.objects['baseballRig'].children)

How about

bpy.context.object.children

?

It will give you all parented meshes, no matter if they got an armature modifier or not. If you wanna check for an armature modifier:

ch = [child for child in C.object.children if child.type == 'MESH' and child.find_armature()]

Note that find_armature() returns a single armature object, even if an object got multiple Armature modifiers.

In addition, an object might have an armature modifier, but isn’t parented to that armature object. If you wanna handle such special cases, the only way is to check against all objects in scene, bpy.context.scene.objects

Hey, thanks, @CoDEmanX. That was my next step. :slight_smile:

That does bring up another question, though…

I tried that line of code in a Python Console, but I don’t understand how to find the results. I tried print(ch) and list(ch), but all it prints out is a pair of square brackets - [].

[] means it’s an empty list

if an object has an armature modifier set but isn’t parented to that armature object, then Armature.children won’t return the object (obviously). Or the object isn’t a mesh-type or the armature couldn’t be found.

Okay, thanks, CoDEmanX. I just did a quick check and none of the objects in the scene I was testing had armature modifiers. I had assumed they did. (Doh!)