Search code examples
maxscript

How to get the order of SubRollouts in MaxScript


I'm trying to access a property of the mainSubRollout for the order the sub rollouts are in.

After running the code below and dragging Sub 2 rollout to the top like the image and checking mainRolTest.mainSubRollout.rollouts it always returns #(Rollout:subRollout1, Rollout:subRollout2) even though the displayed order of the rollouts are not the same.

enter image description here

How can I access this order in which they are currently displayed?

A result for the image should be: #(Rollout:subRollout2, Rollout:subRollout1)

try destroyDialog mainRolTest catch()

(

  rollout subRollout1 "Sub 1" autoLayoutOnResize:true
  (
    button theButton1 "Fake Button 1"
    )

  rollout subRollout2 "Sub 2"  autoLayoutOnResize:true
  (
    button theButton2 "Fake Button 2"
    )

  rollout mainRolTest "..."
  (

    button btn_close "X" align:#right offset:[13,-5]

    SubRollout mainSubRollout "" height:133 width:150 pos:[0,20]

    on btn_close pressed do destroydialog mainRolTest

    )

  createDialog mainRolTest 150 133 style:#() lockHeight:true lockWidth:true
  AddSubRollout mainRolTest.mainSubRollout subRollout1
  AddSubRollout mainRolTest.mainSubRollout subRollout2

  )

-- This always returns #(Rollout:subRollout1, Rollout:subRollout2)
-- Even though the order of the rollouts are not the same
-- How can i access this info?
mainRolTest.mainSubRollout.rollouts

Solution

  • You can always use their actual position:

    fn sortByY A B = (windows.getWindowPos A.hWnd).y - (windows.getWindowPos B.hWnd).y
    rollouts = #() + mainRolTest.mainSubRollout.rollouts
    qSort rollouts sortByY --> 'rollouts' will now be sorted based on Y
    

    If you want the index and don't mind a bit of .NET, it can also be done this way:

    iGlobal = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
    rollupContainer = iGlobal.GetIRollup (UIAccessor.GetParentWindow mainRolTest.mainSubRollout.rollouts[1].hwnd)
    rollupContainer.GetPanelIndex mainRolTest.mainSubRollout.rollouts[2].hwnd
    

    For completeness sake, you can do it through the Qt, too:

    QtWidgets = python.import "PySide2.QtWidgets"
    rolloutWidget = QtWidgets.QWidget.find (UIAccessor.GetParentWindow mainRolTest.mainSubRollout.rollouts[1].hwnd)
    ((rolloutWidget.parent()).layout()).indexOf rolloutWidget