If I define a command object using cmd = DOpus.create.command I can define/redefine the source tab to repetitively execute commands against.
// Begin loop
src = DOpus.listers.lastactive.activetab;
DOpus.output("Source = " + src.path.filepart);
cmd.setsourcetab(src);
n = src.selected.count;
DOpus.output(n + " items selected");
if (n>0) cmd.runcommand("Help About");
if (n>0) cmd.runcommand("Delete");
// End loop
This works as expected across multiple iterations and executes both Help About and Delete whenever one or more items is selected. However, if the command object is defined as cmd = ScriptCommandData.func.command then the same code loop works the first time but only Help About is executed on subsequent iterations; the Delete never works again.
I will attach a demo script that uses a dialog to control multiple iterations. Execute dlgtest1 to run (successfully) with cmd = DOpus.create.command and execute dlgtest1 s1 to run (unsuccessfully) with cmd = ScriptCommandData.func.command. Just CANCEL out of the Delete confirmation to avoid actually deleting anything. You can change selection and/or tab between iterations.
Using a DOpus level command object works so there is a way of achieving what I need. It just strikes me as odd that the prepopulated script level object, which I often use, behaves differently.
My expectation is/was that cmd.SetSourceTab(src); would define or rebuild all of the source components of the command object, whatever its flavour, but that doesn't appear to be the case. I also tried adding src.Update(); beforehand but that doesn't make any difference.
It's prepopulated for the tab you're running from. If you do things to other tabs, creating a new command object or clearing the files out of the old one is best.
It won't. It just sets which tab the command considers the source and runs against. The source and the list of files to affect are separate things with the scripting command object. (Which lets you run commands on files that aren't actually in the tab, or in any tab, if you need to.)
If you run a command without a list of files assigned to it (either explicitly or implicitly from the command object you're given) then Opus might go looking for things to run it against, but it's best not to rely on that as it could be unpredictable.