How to use AddButtonsData.embedded?

Hi,

I want to add embedded command support for dynamic buttons in script commands, but AddButtonsData.embedded always returns an empty string. I don't know if I misunderstand how this property is used, and I haven't found any examples using this property.

I noticed this feature was added in stable version 13.16. I tried installing 13.16, but it still doesn't work. I don't know if I'm using it wrong, or if this feature has never worked correctly.

Here is a simple script that adds the MyCommand command, with the DYNAMIC parameter being the dynamic button parameter.
The output of embedded is an empty string.

function OnInit(initData) {
    initData.name = 'MyDynamicCommand';
    initData.version = '1.0';
    initData.default_enable = true;
    initData.min_version = '13.0';
}

function OnAddCommands(addCmdData) {
    var cmd = addCmdData.AddCommand();
    cmd.name = 'MyCommand';
    cmd.method = 'OnMyCommand';
    cmd.desc = '';
    cmd.label = 'MyCommand';
    cmd.template = 'DYNAMIC/S';
    cmd.dynamic_args = 'DYNAMIC';
    cmd.hide = false;
    cmd.icon = 'script';
}

function OnMyCommand(scriptCmdData) {}

function OnAddButtons(addButtonsData) {
    DOpus.Output('cmdline: ' + addButtonsData.cmdline);
    DOpus.Output('embedded: ' + addButtonsData.embedded);
    var button = addButtonsData.buttons.AddButton();
    button.label = 'My Button';
    return true;
}

my button:

MyCommand DYNAMIC
[Set NOOP]

log:

 MyDynamicCommand:  cmdline: MyCommand DYNAMIC
 MyDynamicCommand:  embedded: 

Thanks.

Thanks, we'll make this work in the next update.

Once the fix is in place it would be nice to see a simple practical example in the documentation.

The example above is probably as simple as it gets :slight_smile:

It's in the beta we put out today:

Added ScriptCommand.supportembedded property. Set to true when adding a dynamic command that you want to be able to support embedded functions.

Thanks Jon and Leo, it works perfectly!

Let me introduce how I’m used.

With embedded commands, the script only needs to do simple parameter replacements when adding buttons, while the actual button commands are defined in the embedded commands.

In this way, if you need to modify the command a button runs, you only need to change the embedded command, without touching the script.

A simple example:

function OnAddCommands(addCmdData)
{
	var cmd = addCmdData.AddCommand();
	cmd.name = "MyCommand";
	...
	...
	cmd.supportembedded  = true; // <-------- set to true
}

function OnAddButtons(addButtonsData)
{
	var embedded = addButtonsData.embedded;
	var paths = [
		"C:\\Users\\",
		"C:\\Windows\\",
		"D:\\"
	];
	for(var i = 0; i < 3; ++i) {
		var button = addButtonsData.buttons.AddButton();
		button.label = paths[i];
        // Use regEx, as JScript does not have the replaceAll() method
		button.func = embedded.replace(/\{\$1\}/g, paths[i]); 
	}
	return true;
}

Button Command:

MyCommand DYNAMIC
[
@keydown:none
Go "{$1}" NEWTAB
@keydown:ctrl
explorer.exe "{$1}"
]

If my script needs to generate dynamic buttons from some paths obtained somewhere, I can just set button.func to the command defined in the embedded command and then replace the parameters, without hardcoding them into the script or passing complex commands through normal parameters.

Hope this helps you :grinning_face:.

Very much so. Thanks.