ScriptSpot

Forum topic · General Scripting

Custom UI register/unregister dialog bar

By Tiger Swallow Style · 2014-12-06

Description

Hi everybody, new to this forum, I'm coding a script to help myself with some stuffs I like to use and for that I'd like to make a floating toolbar, dockable to the Max UI just by clicking/unclicking one button.

I don't know why, but at first this worked (By clicking the button and uncheking it back)

But for some unknown reasons I now got an error without changing anything in the code :

" -- Runtime error: Requires a Rollout or RolloutFloater, got: undefined"

Here is the code :


macroScript Toolbox_Utility_Script
category:"Toolbox Utility"
toolTip:"Toolbox Utility"
(
local isOpen = false


on execute do
  (
    if isOpen then
    (
		cui.UnRegisterDialogBar Toolbox_Utility
		closerolloutfloater Toolbox_Utility
		isOpen = false
    )
    else
    (
		Toolbox_Utility = newRolloutFloater "Toolbox" 160 1024
		cui.RegisterDialogBar Toolbox_Utility style:#(#cui_dock_all, #cui_floatable, #cui_handles)
		cui.DockDialogBar Toolbox_Utility #cui_dock_left
		isOpen = true
    )
  )

  on isChecked return isOpen
)

Thanks for lighting me on this! :)

Comments (1)

MarkD · 2014-12-09

 It seems like you're trying to close a floater that doesn't exist and the script dies? Maybe try using a "Try/catch" instead of just trying to close the rollout floater that may or may not be there?

So instead of:

closerolloutfloater Toolbox_Utility

use:

try (closerolloutfloater Toolbox_Utility) catch ()

That way if it doesn't find a rollout floater it will carry on with the rest of the script.

 

You will also want to try to unregister the DialogBar when you try to close the rollout:

try (cui.UnregisterDialogBar Toolbox_Utility) catch()

Otherwise it just keep adding new rollouts. You might also need to use "DestroyDialog" instread of CloseRolloutFloater?

try (DestroyDialog Toolbox_Utility) catch()