How to output a stringset in context of clickdata.func.command

I believe the command object in this fragment:

Set cmd = clickData.finc.command

Will store commands that should be executed in a stringset
I can output the number of lines (5 as you can see in the screenshot below) in the stringset successfully.
But how can I output the actual strings?
Cannot work it out
Appreciation as always....

It isn't a StringSet, but Command.files is a collection of file Item objects. You can loop through it and print out each item the same as with any other collection.

The default script has examples of how to loop through collections.

1 Like

Hi Leo
I should clarify that I am after the commands themselves (as opposed to the target files on which the commands will be acting).
The default script shows fairly clearly how the collection of files can be parsed.
Does this change your answer at all?
Thanks for any reply..

The Command object acts as a collection of the lines within the command, so you can iterate it like other collections (it's not actually a StringSet, as Leo said, so StringSet-specific methods won't work on it).

1 Like

Hi there

I wonder if I could develop this further.
I want to output the current command i.e. last command added.
In the context of the screenshot from Jon above I want to output line 5
How would I do that?

Thanks,..

Function OnClick(ByRef clickData)
	Set cmd = clickData.func.command
	cmd.AddLine "Line 1"
	cmd.AddLine "Line 2"
	cmd.AddLine "Line 3"
	cmd.AddLine "Line 4"
	cmd.AddLine "Line 5"
	DOpus.Output cmd(cmd.count-1)
End Function
1 Like

Thanks Leo

Hi Opus Magicians
I have used this without ever properly understanding the underlying implementation.
Would anyone know the equivalent of the above code fragment so kindly supplied by @Jon in JS?
That is to print out all the previously added commands to DOpus.Output
Gratitude.

Having done some inexpert googling I tried this

	for (var line in cmd) 
	{
		DOpus.Output("-->" + line);
	}

It does not work.
No error just no effect.
Back to the search engine.....

JScript doesn't have a nice syntax for enumerating collections, unfortunately. You have to use the cumbersome Enumerator object instead. (This is about the only downside of JScript compared to VBScript. The rest of the upsides make up for it.)

The JScript version of the button editor's default script includes some examples of how to do it:

		for (var eSel = new Enumerator(clickData.func.sourcetab.selected); !eSel.atEnd(); eSel.moveNext())
		{
			if (eSel.item().is_dir)
			{
				DOpus.Output("  (d) " + eSel.item().RealPath);
			}
			else
			{
				DOpus.Output("  (f) " + eSel.item().RealPath);
			}
		}

Hi Leo
Thank you. I was never going to pick up on that myself.
In you example I think the code enumerates an item collection of selected files/folders in a lister.
In my case I want to replace that with a command object.
This is my stab at applying the concept to my context.
There is no error but the output shows "undefined" as you can see.
What am I doing wrong?

function OnClick(clickData)
{
    DOpus.ClearOutput;
	DOpus.Output("001000 Start");
	var cmd = clickData.func.command
	//
	cmd.AddLine("Clipboard SET Test");
	DOpus.Output("cmd.Linecount     = " + cmd.Linecount);

	for (var eSel = new Enumerator(cmd); !eSel.atEnd(); eSel.moveNext())
	{
		DOpus.Output("    -->" + eSel.line);
	}
}

001000 Start
cmd.Linecount = 1
-->undefined

Use eSel.item() instead of eSel.line.

Bingo.
Thx @Ixp....