MAXScript Dialogs > Using Custom Attrs as global vars

I am trying to make a Maxscript dialog window for the user to input variables that other scripts will use. I've read the help docs and the relevant posts on this forum, but haven't found the answers to some problems I've run into.

I've been using rootNode custom attributes to store global variables for the dialog. I want to make this a macroscript where the user can press a button on the toolbar and the createDialog will open the dialog UI.

If I evaluate it with the macroscript declaration commented out, it will create the floating window dialog the way I want.

If the macroscript definition is not commented out, it will open the dialog in the Utilities Panel.

If the macroscript definition is in the first line of code and I run it from a toolbar button, my custom attributes on the rootNode are not created and the dialog errors out.

How can I get this to run from a toolbar button, open up as a dialog, and create/utilize the rootNode custom attributes correctly? Expecting the user to evaluate it by pressing ctrl+E is unacceptable. Currently, that's the only way I can get it to work.

Thanks!

(
------------------------------Rollout----------------------------------------------
try(DestroyDialog myRollout)catch()
 
	rollout myRollout "Rollout"
	(
		group "Time Range"
		(
			radiobuttons timeRangeButton labels:#("Start","Start/End","Current", "Clipboard") default:4
			on timeRangeButton changed arg do
			(					
				rootNode.timeRange = case arg of
				(
					1: "start"
					2: "startEnd"
					3: "current"
					4:"clipboard"
				)
			)	
		)
	)
 
------------------------------Rollout Initialization---------------------------------------
 
	on execute do
	(
		addRollout myRollout
 
		if custAttributes.count rootNode == 0 then 
		(
			myAttrib = attributes CAMyCustAttrib
			(
				parameters main 
				(
					timeRange type:#string default:"clipboard" animatable:false
				)
			)
			custAttributes.add rootNode myAttrib
		)
 
		else if custAttributes.count rootNode != 0 then 
			for c in rootNode.custAttributes do
				if hasProperty c "timeRange" then 
					(
						mySelected = #("start", "startEnd", "current", "clipboard")
						myRollout.timeRangeButton.state = findItem mySelected rootNode.timeRange
					)
	) 
----------------------------------Macroscript Definition--------------------------------	
--macroScript simpleRolloutTest category:"Tools"
(
	CreateDialog myRollout 200 330
)
)