Using GUI created dialogs in custom command via "Standard Function" button script?

I made a custom "add-in" command, implemented in JScript, which I like to call via "Standard Function" button scripts.
Now, I'd like to use a Dialog in it that I'd like to build in the Resources->Dialogs UI.
Problem is, that tab and Resources in general only seem to be available to "Script Function" button scripts.
I tried calling the command from a Script Function's clickData.func.command.RunCommand(), but even that fails with

Invalid procedure call or argument (0x800a0005)

Is there a way to use GUI built dialog templates in these custom commands?
If not, I'd like to hereby register a feature request :slight_smile:

Scripts that live inside buttons or hotkeys are not available outside of those buttons or hotkeys.

But if you move the code/dialog into a script add-in, you can run it from anything. (You lose the dialog editor then but can copy & paste things back & forth to edit them. Makes sense to wait until the dialog/code is finished before moving it. This is also something we plan to improve in the future.)

1 Like

Mr. Neversleeps to the rescue :)))
I figured there must be a way to use the generated XML somehow, but I couldn't find anything useful among the first results googling things like "directory opus dialog xml in custom command" or "directory opus custom command use dialog template".
How do I do that?

NVM, I found it now:
Calling Script.LoadResources(<XML String>) makes the resource available in the script's context just like it would be in a Script Function! Neato!

The Script object is one of the two global script objects provided by Opus. This object is provided to script addins when their various event handlers are invoked (other than for the OnInit event). It provides information relating to the script itself.

Bonus: since my command has an "open" template using the /M "multiple" argument type, I can just append the resources I want imported as strings (be sure to remove line breaks and replace double quotes with single quotes, or escape them somehow, and you're good to go), and then I can just parse all the superfluous parameters as resources!

args = colToArray(commandData.func.args.CMD); // <- (Just a function that converts the DOpus collection type to a regular JScript array because I don't like dealing with these not-entirely-implemented-in-JScript type interfaces)

if(args.length>argNum){ // argNum = Number of your regular arguments
	for(var i = argNum; i<args.length; i++){
		var s = args[i];
		Script.LoadResources(s);
	}
}

That's really handy, thank you for making that possible :+1:

You can also include the XML after the script in the same text file:

https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/Resources.htm

1 Like

That's probably the best way to do things for most cases.
But for my current needs, I find it even better to pass the string along, since I use a general custom command to run different scripts, and this gives me the possibility to specify the script and its resources right in the button :black_heart:

1 Like