Blender 2.70 wrecked my script

Well, it’s not much of a script but I need it for fine tuning a ragdoll system I’m working on. The offending line is:

for bone in bpy.context.active_object.pose.bones:

It generates a NonType error now. It was working perfectly in 2.6x. The script toggles constraints on all the bones of the selected armature on and off. I notice that autocomplete no longer gives me any options after “bpy.context.active_object.pose”. I’m not a scripter so I’m not sure where to go to find any changes I should be aware of. Any help would be gratefully accepted.

It is kind of poor coding practice to just blindly operate upon an assumption, such as the active object being valid. You need to “bullet-proof” your code a bit. Your error might have been None type instead of NonType, IDK.

Try something like this.


ob = bpy.context.active_object
if ob != None:
    for bone in ob.pose.bones:
        #Do work.
        pass
else:
    # I do not have an active object.
    pass

You shouldn’t rely on the context.object being set, a None value is a common case - and has nothing to do with 2.70.

ob = bpy.context.object
if ob is not None and ob.type == 'ARMATURE':
    for pbone in ob.pose.bones:
        # ...

If it’s an operator, use the condition check in its poll() classmethod

Thanks for the replies. Atom, I have the armature selected when I run the script. “None type” as opposed to NonType I don’t understand - except to say you inspired me to put the armature into object mode and then run the script. And it worked. My script already identifies the object as armature and then toggles into pose mode if need be. In earlier versions it would work from either object or pose mode. CoDEmanX, noted (and thank you), but way beyond my ability or needs at the moment. So, one last question: how do I mark this thread as solved?

You can mark the thread as solved by editing your first post and selecting the appropriate prefix.