Someone asked if it’s possible to have some rollups opened by default and others closed. That’s my attempt to tackle the issue.
While it seems to work overall, sometimes I get undefined trying to get IRollupPanel using IRollupWindow.GetPanel method (line:19). Any thoughts on what could be the cause of it?
And the main question is: How these IRollupWindow and IRollupPanel instances should be handled after work is done? Should I dispose them or what?
fn rollupDoorman forceOpenRollups: = (
if forceOpenRollups == unsupplied do forceOpenRollups = #("Selection","Edit Vertices","Edit Edges","Edit Geometry","Edit Borders","Edit Polygons","Polygon: Smoothing Groups","Polygon: Material IDs")
modPanelHWND = undefined
for c in UIAccessor.GetChildWindows (windows.getMAXHWND()) while modPanelHWND == undefined where (d = windows.getHWNDData c)[4] == "ModifyTask" do modPanelHWND = d[1]
rollupWindows = for w in windows.getChildrenHWND modPanelHWND where w[4] == "RollupWindow" collect w[1]
for rollupWindowHWND in rollupWindows do (
IRollupWindow = (dotnetclass "Autodesk.Max.GlobalInterface").Instance.getIRollup (dotnetobject "system.intptr" rollupWindowHWND)
-- format "
IRollupWindow.numpanels: %
" IRollupWindow.numpanels
for i=0 to IRollupWindow.numpanels-1 do (
IRollupPanel = IRollupWindow.GetPanel (IRollupWindow.GetPanelDlg i asdotnetobject:true)
if IRollupPanel == undefined do (format "Failed at %
" i; continue)
rollupName = UIAccessor.GetWindowText IRollupPanel.TitleWnd
-- format "%: %
" i rollupName
if findItem forceOpenRollups rollupName > 0 then (
if not IRollupWindow.IsPanelOpen i do IRollupWindow.SetPanelOpen i true false
) else (
if IRollupWindow.IsPanelOpen i do IRollupWindow.SetPanelOpen i false false
)
)
)
)
fn weAreOpenHandler = (
local base = modPanel.getCurrentObject()
case classof base of (
Editable_Poly: rollupDoorman()
Edit_Poly: rollupDoorman()
Editable_Mesh: rollupDoorman()
Edit_Mesh: rollupDoorman()
default:()
)
)
callbacks.removeScripts #modPanelSelChanged id:#weAreOpen
callbacks.removeScripts #ModPanelSubObjectLevelChanged id:#weAreOpen
callbacks.addScript #modPanelSelChanged "weAreOpenHandler()" id:#weAreOpen
callbacks.addScript #ModPanelSubObjectLevelChanged "weAreOpenHandler()" id:#weAreOpen