4
$\begingroup$

I can't understand some type definitions like

bones Type: ArmatureBones bpy_prop_collection of Bone, (readonly)

link: https://docs.blender.org/api/current/bpy.types.Armature.html#bpy.types.Armature.bones

What is this type? Type should be simply one word. Why this one?

ArmatureBones bpy_prop_collection of Bone

We suppose to get data based on the reference section like this one, but I can't find bpy.context.armature.

Can you shed a light one this?

C.armature

Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
AttributeError: 'Context' object has no attribute 'armature'

enter image description here

Here are some variables also shown in manual, but I can't get them from my context. I find difficult to understand this manual. I want to show you, but (I can't pose another picture. " You need at least 10 reputation to post more than 2 links?!" I just want to add another picture). Anyway it is listed in the manual as:

bpy.context.bone

Type: bpy.types.Bone

bpy.context.edit_bone

Type: bpy.types.EditBone

bpy.context.pose_bone

Type: bpy.types.PoseBone

It comes out that I can't find C.bone or C.pose_bone in console. Then why are they listed in this manual?

$\endgroup$
5
$\begingroup$

Don't worry, learning to read an API is a skillset unto itself, and a non-trivial endeavor at that, so it's okay for it to feel daunting. Unfortunately, it's usually necessary.

To answer your first question, ArmatureBones is a member of armature. It is a container, but it's not a built in Python container like list or tuple. It's a Blender container of type bpy_prop_collection, and this instance of that type of container contains Bones.

This would be roughly equivalent to saying "Encyclopedia is list of Books."

To answer your second question, there are a number of different types of context. Without knowing which one you're referencing it's hard to guess. However, there is a screen context, and it makes sense that a screen doesn't have an armature. So if you're referencing one of those other contexts, it'd make sense for it to has no attribute 'armature'.

Furthermore, the context that does have an armature is the buttons context, which means it's probably not the armature you're looking for. I suspect that you're actually after bpy.data.objects["name_of_your_rig"].data as referenced in this answer over here.

I hope that helps!

$\endgroup$
  • $\begingroup$ Thank you. I feel much better from your explanation. Another question is that if there are a number of contexts, what doesn the bpy.context in python console return. How can we know if the context from "bpy.context" a button one or a scene one? For example, I called bpy.context with one bone selected in pose mode. What context will be returened in this scenario? $\endgroup$ – Sergius Liu Aug 7 '17 at 16:45
  • $\begingroup$ I think bones is a member of Armature instead of ArmatureBones. Because, I tried to use C.object.data.ArmatureBones which can't be accessed but C.object.data.bones can be found. So I assume bones is a member whose type is bpy_prop_collection of Bones. Then what is ArmatureBones here? $\endgroup$ – Sergius Liu Aug 7 '17 at 17:09
  • $\begingroup$ You're right, Bone is a member of Armature. There's a container that's also a member of Armature, and it contains the Bones that belong to a particular instance of Armature. The container is a bpy_prop_collection called "ArmatureBones." $\endgroup$ – Matt Aug 7 '17 at 17:25
  • $\begingroup$ I'll see if I can write something up about context after lunch... $\endgroup$ – Matt Aug 7 '17 at 17:25
  • $\begingroup$ The data type context members are often only available to the PROPERTIES space. eg select an armature object, go to the data panel (with the little armature icon) rt click on "view source" over the armature name .. and low and behold arm = context.armature. You'll find there is a context.mesh context.speaker etc etc for other data types, but only when coding in this (properties) space. $\endgroup$ – batFINGER Aug 7 '17 at 18:45

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.