@Hans-v-Buitenen ,
This is the way Notepad++ works. If you have it in multi-instance mode, then each individual call to notepad++.exe opens a new instance with all the files given in the argument to that specific Notepad++ instance. You cannot pick and choose which already-running instance will get a new file (and I’ve never seen a multi-instance application that allows pick-and-choose of the destination window from the command line).
In theory, you could make a feature request (per this linked FAQ) to ask for a way to pick a destination instance in multi-instance mode, but my guess is that it would be quite difficult to implement, and I don’t know whether you’d get traction with the developer(s). If you do create a feature request, make sure to paste a link to the issue in this discussion.
Otherwise, you will need to build up a list of files that you want in the same instance, and either send them as arguments to a single run of notepad++.exe, or build a session file and ask notepad++.exe to open that session – but either way, it would need to wait until your script has gone and found all the files that it wants to group together. I’m not sure how that would take more than a second or two for any script to find; unless you’re trying to find a handful of files in thousands upon thousands of files, or from some slow remote server. For example, if your script currently says (in pseudocode)
for file in all_files:
if file meets criteria then
launch `notepad++.exe file`
end_if
next file
then you could tweak it to say
list_of_files = []
for file in all_files:
if file meets criteria then
append file to list_of_files
end_if
next file
launch `notepad++ list_of_files`
That’s not really a huge change to the coding of the script.
Or, if you want everything in one instance anyway, don’t bother with multi-instance. Then, running new notepad++.exe commands will just add files to the one master instance.
Or, if you really need multiple instances, open multiple instances, then from inside each instance, use one of the scripting plugins (like NppExec or PythonScript) to select and open files for that instance. By driving it from inside each instance, then files would be opened in the correct instance.