You will have to turn the script of @RPaladin to an addon by inserting the bl_info dictionary. blender\3.2\scripts\templates_py\addon_add_object.py. Then you either drop it to where the rest of Blender scripts are or install it from the preferences GUI.
PS. Also if you run the script yourself from text editor, you will have to place an extra register() at the end so you invoke the function manually. Though as said if you turn the file to addon the __main__ call prevails by default.
Ok, so there was an error. I made it work through this Modal template. But now it turned out that bpy.context.region_data.view_location ignores viewport zoom level, which isn’t ideal. Any way to correct it?