Script for setting selected objects a specific Pass Index Number

Hello, i’m trying to make a script to set the Pass Index Number of all selected objects, but i dont know how to make blender get all selected objects and then set the pass index, i made the script to show up on Object Menu of the 3D View, like so:

import bpy

class SetPassIndex(bpy.types.Operator):
“”“Set Pass Index”""
bl_idname = “object.passindex_set”
bl_label = “Set Pass Index”

def execute (code where the actual pass index is set to all selected objects) 

def add_object_button(self, context):
self.layout.operator(
SetPassIndex.bl_idname,
text=SetPassIndex.doc,
icon=‘PLUGIN’)

def register():
bpy.utils.register_class(SetPassIndex)
bpy.types.VIEW3D_MT_object.append(add_object_button)
if name == “main”:
register()

I want to make a small window that pops up when selecting this item on the Object Menu, with two arrows that allows the user to select a specific number to set.
I dont know if everything is correct, but, any help apreciated. Thanks in advance.

Here you go, using invoke_props_dialog():

import bpy

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    bl_options = {'REGISTER', 'UNDO'}
    
    pass_index = bpy.props.IntProperty(name="Pass Index", subtype='UNSIGNED')


    def execute(self, context):
        for ob in context.scene.objects:
            ob.pass_index = self.pass_index
        return {'FINISHED'}
        
    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self)




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




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




if __name__ == "__main__":
    register()


    # test call
    bpy.ops.object.simple_operator('INVOKE_DEFAULT')

Thank you so much man!