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

**URL:** https://resource.dopus.com/t/using-gui-created-dialogs-in-custom-command-via-standard-function-button-script/38259
**Category:** Help & Support
**Tags:** script
**Created:** [April 4, 2021, 1:44pm UTC](https://resource.dopus.com/t/using-gui-created-dialogs-in-custom-command-via-standard-function-button-script/38259 "2021-04-04T13:44:55Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![svArt](https://resource.dopus.com/user_avatar/resource.dopus.com/svart/32/12646_2.png) [@svArt](https://resource.dopus.com/u/svArt)
#### Post date: [April 4, 2021, 1:44pm UTC](https://resource.dopus.com/t/using-gui-created-dialogs-in-custom-command-via-standard-function-button-script/38259/1 "2021-04-04T13:44:55Z")

</div>

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 🙂

---

<div class="post-metadata">

### Author: ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)
#### Post date: [April 4, 2021, 1:53pm UTC](https://resource.dopus.com/t/using-gui-created-dialogs-in-custom-command-via-standard-function-button-script/38259/2 "2021-04-04T13:53:25Z")

</div>

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.)

---

<div class="post-metadata">

### Author: ![svArt](https://resource.dopus.com/user_avatar/resource.dopus.com/svart/32/12646_2.png) [@svArt](https://resource.dopus.com/u/svArt)
#### Post date: [April 4, 2021, 1:57pm UTC](https://resource.dopus.com/t/using-gui-created-dialogs-in-custom-command-via-standard-function-button-script/38259/3 "2021-04-04T13:57:35Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![svArt](https://resource.dopus.com/user_avatar/resource.dopus.com/svart/32/12646_2.png) [@svArt](https://resource.dopus.com/u/svArt)
#### Post date: [April 4, 2021, 2:41pm UTC](https://resource.dopus.com/t/using-gui-created-dialogs-in-custom-command-via-standard-function-button-script/38259/4 "2021-04-04T14:41:27Z")

</div>

NVM, I found it now:  
Calling **[Script](https://www.gpsoft.com.au/help/opus12/Documents/Scripting/Script.htm).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](https://www.gpsoft.com.au/help/opus12/Documents/Scripting/Script_Addins.htm) when their various event handlers are invoked (other than for the [**OnInit**](https://www.gpsoft.com.au/help/opus12/Documents/Scripting/OnInit.htm) event). It provides information relating to the script itself.

Bonus: since my command has an "open" template using the /M "multiple" [argument type](https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Argument_Types.htm), 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 👍

---

<div class="post-metadata">

### Author: ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)
#### Post date: [April 4, 2021, 3:17pm UTC](https://resource.dopus.com/t/using-gui-created-dialogs-in-custom-command-via-standard-function-button-script/38259/5 "2021-04-04T15:17:56Z")

</div>

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](https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/Resources.htm)

---

<div class="post-metadata">

### Author: ![svArt](https://resource.dopus.com/user_avatar/resource.dopus.com/svart/32/12646_2.png) [@svArt](https://resource.dopus.com/u/svArt)
#### Post date: [April 4, 2021, 3:27pm UTC](https://resource.dopus.com/t/using-gui-created-dialogs-in-custom-command-via-standard-function-button-script/38259/6 "2021-04-04T15:27:18Z")

</div>

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 🖤
