How to use a messagebox in a for loop?

Hi all!

So I want to loop thru all bones in an armature and pop up a dialog that will allow me to enter a new name for the bone. The code I have was originally wrote in blender 2.76, and I’ve updated it to 3.6.

My messagebox code:

class MessageBox(bpy.types.Operator):
    bl_idname = "message.messagebox"
    bl_label = "label"
    
    message : bpy.props.StringProperty(
        name = "message",
        description = "message",
        default = ''
    )
    
    def execute(self, context):
        # toggle in & out of edit mode to force screen 
        # update with name change
        bpy.ops.object.mode_set(mode="EDIT")
        bpy.ops.object.mode_set(mode="POSE")

        return {'FINISHED'}
    
    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self, width = 300)
    
    def draw(self, context):
        self.layout.label(text = "Change Bone Name")
        self.layout.prop(context.active_pose_bone, "name", text = "New Name")
        
# end of - class MessageBox(bpy.types.Operator):

I call this messagebox from an operator that loops thru all the bones in the armature:

for index in bones:
            bpy.context.object.data.bones.active = bpy.context.object.pose.bones[index.name].bone
            bpy.ops.message.messagebox(message = index.name)
            bpy.ops.message.messagebox('INVOKE_DEFAULT')

This code worked in 2.76, but it created a UI messagebox for each bone. 4 bones, 4 popups, 100 bones, 100 popups. I didn’t like this because I’m thinking at some point there might be a limit as to how many popups can be created. Seems like bad practice, but it worked.

Now, in 3.6 the code creates a popup for each bone, but only the first popup works. Every popup after the first one is a duplicate of the first one.

Thinking now I need to create each popup uniquely - like with a bone name added to it. Not sure how to do that in python, how do I create a new instance of the messagebox for each bone?

Or, a way to pause the for loop to wait on user input…

Thanks for any help!
Randy

I think its a classic issue of redefining the variable every time you run the loop. So when the code is executed only the last index is assigned. See https://stackoverflow.com/questions/65542607/for-loop-only-returns-last-value

You can also circumvent it with a lambda I think. If I understand correctly 2.76 was version 2.x and this specific behaviour changed in Python v3.x.