Suggestion: ArgsMap Object

As an alternative to the Args object, a map of arguments would provide a simple way of establishing how many were specified and the ability to process them by enumeration. For example:

ArgsMap.count = 4;

for (var e = new Enumerator(ArgsMap); !e.atEnd(); e.moveNext())
{
	var key = e.item();
	var value = map(key);
	DOpus.Output(key + " -> " + value);
}

somebool -> true
somestring -> hello world
someinteger -> 12
somevector -> vector object, e.g.
somevector(0) = the quick
somevector(1) = brown fox
somevector(2) = etc
1 Like

Sometimes it would also be useful to have an ArgString option which returns everything typed after the command as a string. e.g.

myCmd The quick brown fox jumps over the lazy dog

DOpus.ArgString = The quick brown fox jumps over the lazy dog

What about just a Set of used argument names? You could then loop through that and get the values or other details out of the normal Args object.

As well as normal argument parsing, or instead of*?

(* Which would be like having a single, default /R raw argument if that was possible. I don't think it is currently since there's no way to make something default if it's already /R right now.)

Yes, that makes sense.

As well as. It would provide a simple way for a user command to process a supplied string without having to be concerned about parsing against a template or prefixing with an argument name.

But you wouldn't want to use both modes at the same time with the same command, I'm assuming?

Correct. You would use one or the other depending on what your script does.

1 Like

Nice idea, we'll add the ArgsMap thing in the next update.

You can actually get the original command line already, from the cmdline property of the ScriptCommandData object.

Very good. I never knew about the cmdline property. After reading the relevant section in the help file and trying it out for myself, can I suggest that you also document the cmdline property in the ClickData section which describes func but not cmdline.

cmdline isn't part of ClickData, which is passed to script buttons. Script buttons don't have command line templates or arguments at all. (You can't pass arguments to a button; only to a command run within a button or script.)

cmdline is only part of ScriptCommandData, which is passed to script commands.

Of course, makes perfect sense. Thanks for the clarification.