Can't get modifier when custom button is script

<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>test GetModifiers</label>
	<icon1>#newcommand</icon1>
	<function type="script">
		<instruction />
		<instruction>@nodeselect</instruction>
		<instruction>@script VBScript</instruction>
		<instruction>Option Explicit</instruction>
		<instruction>Function OnClick(ByRef clickData)</instruction>
		<instruction>	DOpus.ClearOutput</instruction>
		<instruction>	Dim cmd, mm, m</instruction>
		<instruction>	&apos; ---------------------------------------------------------</instruction>
		<instruction>	Set cmd = clickData.func.command</instruction>
		<instruction>	Set mm = cmd.GetModifiers</instruction>
		<instruction>	dopus.output mm.count</instruction>
		<instruction>	for each m in mm</instruction>
		<instruction>		dopus.ouotput m &amp; &quot; = &quot; &amp; mm(m)</instruction>
		<instruction>	next</instruction>
		<instruction>	&apos;cmd.deselect = false &apos; Prevent automatic deselection</instruction>
		<instruction>	DOpus.Output &quot;@nodeselect = &quot; &amp;  mm(&quot;@nodeselect&quot;) </instruction>
		<instruction>End Function</instruction>
	</function>
</button>

error: 'mm' (0x800a0009)

Command.GetModifiers is returning an empty map in this situation, so mm("@nodeselect") doesn't exist and will cause an error.

Using the @nodeselect modifier and GetModifiers doesn't really make sense in a script that is directly inside a button, since you can just edit the script itself to change that. (You already have the relevant code commented out.)

GetModifiers is there so that commands added by Script Add-Ins can find out which modifiers are set on the buttons which run their commands:

Returns a Map of the modifiers that have been set for this command (either by the SetModifier method, or in the case of script add-ins any modifiers that were set on the button that invoked the script).

When a Script Add-In adds a command, it can be run from any button, and the different buttons might use different modifiers. But there is no script add-in here, and only one button. What you have is a Script Function where the script is directly in one button and can't be run from any other button.

1 Like