Global Variable Buttons

An esoteric pair of buttons which came in handy while I was playing with Global Variables for an earlier post.

The first button will open the Script Log and show all currently available Global Variables (and their contents). The second button will delete all Global Variables (note: the delete will just cycle through and delete all variables and doesn't allow any choice over it).

For more control over Global Variables then Global Variable Management Dialog is a much more elegant solution.

Show Global Variables

function OnClick(clickData)
{
	cmd = clickData.func.command;
	cmd.RunCommand('Set LISTERSIZE=Set UTILITY=OtherLog');

	var count = 0;
	
	DOpus.ClearOutput();
	DOpus.Output("Global Variables:");

	for (var eVars = new Enumerator(DOpus.Vars); !eVars.atEnd(); eVars.moveNext())
	{
			varContent = DOpus.Vars.Get(eVars.item());
			DOpus.Output("    " + eVars.item() + " = " + varContent);
			count = count + 1;
	}

	DOpus.Output("Total: " + count);
}

Delete Global Variables

function OnClick(clickData)
{
	cmd = clickData.func.command;
	cmd.RunCommand('Set LISTERSIZE=Set UTILITY=OtherLog');

	var count = 0;

	DOpus.ClearOutput();
	
	for (var eVars = new Enumerator(DOpus.Vars); !eVars.atEnd(); eVars.moveNext())
	{
			varContent = DOpus.Vars.Get(eVars.item());
			DOpus.Vars.Delete(eVars.item());
			count = count + 1;
	}
	DOpus.Output("Global Variables Deleted: " + count);
}

Show Global Variables.dcf (1.2 KB)
Delete Global Variables.dcf (1.2 KB)

(Scripting boffins - is there a way to get the total count of items in the enumeration results without resorting to count = count + 1; ???)

DOpus.Vars.count will tell you how many things are in DOpus.Vars

1 Like

Thanks @Leo. Sometimes the obvious isn’t obvious. :grinning:

1 Like