[Closed] How to add a toolbar to the UI via maxscript
Hi guys,
I’m writing an installer for a script of mine.
Everywhere I looked people were saying that you could not add a toolbar to the UI via script.
Anyway, I was able to do it and thought I might share the code.
I’m fairly new to this kind of thing so I’d be happy to hear any feedback you might have.
The trick was using the callback #postSystemShutodwn to modify the “CUIData” “WindowCount”, setting of cui.getConfigFile() (MaxStartUI.cui) which would otherwise get saved over by max, reverting any changes you made.
ps… Use at your own risk, I would suggest backing up your cui file before testing this.
Ive tried it with max 2010 and 2011 so far.
global maxStartUIFile = ""
global incrementCuiDataCountStr = ""
function addToolbarUi =
(
maxStartUIFile = cui.getConfigFile() -- finds the UI file location
-- Set the [CUIWindows] "F00n = T:NAMEOFYOURTOOLBAR"
cuiWindowsAr = getINISetting maxStartUIFile "CUIWindows" -- gives an array of all entries F000, F001 etc
nextCuiWindowsInt = cuiWindowsAr.count -- how many in array,
concatenate = (formattedprint nextCuiWindowsInt format:"03d") -- no need to add 1 because first entry is 000
nextCuiWindowsString = "F" + (concatenate as string) -- now have F00n
setINISetting maxStartUIFile "CUIWindows" nextCuiWindowsString "T:NAMEOFYOURTOOLBAR" -- add to ini, F00n
-- Set the [CUIData] "WindowCount = n+1"
CuiDataCountStr = getINISetting maxStartUIFile "CUIData" "WindowCount" -- always a number 1 higher than existing F00n
CuiDataCountInt = CuiDataCountStr as integer -- make it an Int
incrementCuiDataCountStr = (CuiDataCountInt += 1) as string -- add 1 for later use in postSystemShutdown callback
if uiEditFailing == false then
(
-- Since the only part of the maxStartUIFile that seams to be overwritten is the [CUIData] WindowCount, This is the only bit that needs saving on shutdown
callbacks.addScript #postSystemShutdown "setINISetting maxStartUIFile \"CUIData\" \"WindowCount\" incrementCuiDataCountStr"
)
else
(
messagebox "Attempts to edit the user interace file configFile failed. Try manual installation of toolbar"
)
-- Adding the [NAMEOFYOURTOOLBAR] toolbar info
setINISetting maxStartUIFile "NAMEOFYOURTOOLBAR" "Rank" "307"
setINISetting maxStartUIFile "NAMEOFYOURTOOLBAR" "SubRank" "2"
setINISetting maxStartUIFile "NAMEOFYOURTOOLBAR" "Hidden" "0"
setINISetting maxStartUIFile "NAMEOFYOURTOOLBAR" "FRect" "310 314 611 375"
setINISetting maxStartUIFile "NAMEOFYOURTOOLBAR" "DRect" "1235 93 1536 132"
setINISetting maxStartUIFile "NAMEOFYOURTOOLBAR" "DRectPref" "2147483647 2147483647 -2147483648 -2147483648"
setINISetting maxStartUIFile "NAMEOFYOURTOOLBAR" "DPanel" "1"
setINISetting maxStartUIFile "NAMEOFYOURTOOLBAR" "Tabbed" "0"
setINISetting maxStartUIFile "NAMEOFYOURTOOLBAR" "TabCt" "0"
setINISetting maxStartUIFile "NAMEOFYOURTOOLBAR" "CurTab" "-1"
setINISetting maxStartUIFile "NAMEOFYOURTOOLBAR" "CurPos" "1 1235 93 1536 132"
setINISetting maxStartUIFile "NAMEOFYOURTOOLBAR" "CType" "1"
setINISetting maxStartUIFile "NAMEOFYOURTOOLBAR" "ToolbarRows" "1"
setINISetting maxStartUIFile "NAMEOFYOURTOOLBAR" "ToolbarType" "3"
setINISetting maxStartUIFile "NAMEOFYOURTOOLBAR" "ItemCount" "9"
setINISetting maxStartUIFile "NAMEOFYOURTOOLBAR" "Item0" "2|0|0|31|3|647394|BUTTONNAME`TOOLBARNAME|0|0|\"BUTTONLABEL\"|\"BUTTONLABEL\"|-1|"
-- etc etc, for all your tool buttons, go set up your toolbar manually to see the structure of the .cui file. Then just copy it over to here using the above format.
)
I don’t know if there is a need to use the postsystemshutdown callback.
I’ve done a similar thing but the changes are updated instantly:
colorman.reInitIcons() --load the new icons if you added any
cui.loadconfig current_CUIfile --load the new edited UI config file
Cool I’ll try that out and see if it simplifies things.
Thanks
.
Update 1
Not having any luck so far… Are you saving to the same currently used cui file? or do you create a copy, edit that then load that new one in?
I’m trying the first option and it doesn’t remain modified
Update2.
My bad! Ignore update1. It’s working…
Thanks again.