Script command only running on first of all selected files

I'm writing a Script Add-in which defines an internal script command so it can be used with a button. Unfortunatly, when I click the button the command only runs on the first of all selected files. I've tried several options (@async / @sync), but nothing works. To test if this is some kind of bug, I've created a bare script called "ScriptTest.js" in the users "AppData\Roaming\GPSoftware\Directory Opus\Script AddIns" directory:

function OnInit(initData) {

var cmd = initData.AddCommand();
cmd.name = "ScriptTest";
cmd.method = "OnScriptTest";
cmd.template = "FILE/K";

}

function OnScriptTest(funcData) {

DOpus.OutputString(funcData.func.args.file);

}

When I create a button with the function "ScriptTest FILE {f!}", it only logs the name of the first file, the function isn't called for all the other files which are selected...

I'd really appreciate it if someone can explain to me how to fix this?

Script commands are not called for every selected file, you need to loop over the selected files yourself within the script.
Lookup the funcData.func.sourcetab.selected collection and the example given in this forum on how to do this.

Alternatively you can create a usercommand "ForEach", which is what I came up with to get around this behaviour when needed.


Call your script command as you would, just add "ForEach" in front of it and you get the behaviour you were expecting.

Thanks for the quick reply tbone, you're ForEach work around worked!

A suggestion to the DOpus developers: as this is a work around, it would be great if DOpus would have an internal Modifier to invoke this behaviour?

Also, this behaviour doesn't show up in the documentation, as far as I have seen?