how could I turn active a bone in ui header? (blender 2.79) I want to make something like a feedback tool, but I can't assign the active bone in the ui Header.

What could I do to achieve it?

this is the code:

bl_info = {
    "name": "UI_Study",
    "description": "Study.",
    "author": "José Vargas",
    "version": (1, 0),
    "blender": (2, 79, 0),
    #"location": "VIEW3D_HT_header",
    #"warning": "", # used for warning icon and text in addons panel
    #"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
    #            "Scripts/My_Script",
    #"tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
    "support": "JV",
    "category": "Armature",
}

import bpy

class VIEW3D_HT_issue(bpy.types.Header):
    bl_space_type = 'VIEW_3D'

    def draw(self, context):
        layout = self.layout

        row = layout.row(align = True)

        obj = context.active_object
        s_bones = context.selected_pose_bones
        bone = context.active_bone  
        mode = obj.mode

        if mode == 'POSE':
            if len(s_bones) &gt; 1:
                row.alert = True
                ### remove it and use below
                row.prop(bone,"use_deform",text = "DEF", icon = "GROUP_VERTEX")

                for b in s_bones:
                    b_nam = b.name
                    # armature
                    arm = bpy.data.armatures[obj.name]
                    # get the bone
                    d_bone = arm.bones.get(b_nam)  
                    # make it active
                    ### star issue
                    arm.bones.active = d_bone                      
                    # check if it the active bone is using deform       
                    bone = context.active_bone  
                    # count the bones with use deform active              
                    if bone.use_deform == True:
                        conta += 1 
                # all     
                if conta == len(s_bones):   
                    rrow.prop(bone,"use_deform",text = "DEF", icon = "FILE_TICK")                          
                # ones 
                elif conta &gt; 0 and conta != len(s_bones): 
                    row.prop(bone,"use_deform",text = "DEF", icon = "ERROR")     
                # no ones
                elif conta == 0:
                    row.prop(bone,"use_deform",text = "DEF", icon = "CANCEL")     
                ##### end issue               
            else:  
                # this works well             
                row.alert = False
                if bone:
                    if bone.use_deform == True:            
                        row.prop(bone,"use_deform",text = "DEF", icon = "FILE_TICK")
                    else:                
                        row.prop(bone,"use_deform",text = "DEF", icon = "CANCEL")


def register():
    bpy.utils.register_class(VIEW3D_HT_issue)


def unregister():
    bpy.utils.unregister_class(VIEW3D_HT_issue)


# para correrlo como script
if __name__ == "__main__":
    register()



this is the error:

line 45, in draw
AttributeError: Writing to ID classes in this context is not allowed: Armature, Armature datablock, error setting Armature.active


the file:
https://blend-exchange.giantcowfilms.com/b/KjNApQ8D
Select active bone in pose mode from UI

Use the draw method to draw UI elements only Cannot set properties of ID elements in draw method (the error arm.bones.active = d_bone ). 

In general, Use operators or property update methods to assign values

To set the active bone in pose mode from the UI, can simply put the "active" property of the armature bones collection into the layout.

Below I've used a UI_Layout.prop_search there may be a template that also does similar.

    def draw(self, context):
        layout = self.layout

        obj = context.object
        arm = obj.data

        row = layout.row()        
        row.prop_search(arm.bones, "active", arm, "bones")