I need script to do selective deletes

If I've interpreted your requirements correctly I think this script will do what you want. Let me know if I've misunderstood something.

1000.xxx and 1003.yyy will be deleted. 1001.yyy and 1002.xxx will remain because they have matching .aaa files.

MagicExt = ".aaa"

Function OnClick(ByRef clickData)
	Set cmd = clickData.func.command
	cmd.deselect = False

	Set setMagic = DOpus.Create.StringSetI
	
	For Each file In cmd.files
		If file.ext = MagicExt Then
			setMagic.insert(file.name_stem)
			cmd.RemoveFile(file)
		End If
	Next

	For Each file In cmd.files
		If setMagic.exists(file.name_stem) Then
			cmd.RemoveFile(file)
		End If
	Next

	' remove this loop once you're satisfied the script works correctly
	For Each file In cmd.files
		DOpus.Output "Will delete: " & file
	Next

	' uncomment this line to delete for real
	'cmd.RunCommand("delete")
	
End Function