Search code examples
pythonselection3dsmaxmaxscript

3dsmax maxscript: How do I get an array/list of verts in the order I selected them?


I'm writing a tool for 3dsmax that requires a user to get selected vertices in the order they were selected in an array, but so far passing this returns vertices in their created order:

sel = getCurrentSeletion()
selvets = vsel[1].selectedVerts

How would I get selected vertices in the order I selected them in 3ds max, using maxscript?

If there is no way in maxscript, is there a way to do that in python?


Solution

  • If you only care about the positions of the verts, you can use pickPoint function instead. Otherwise make a callback that updates on selection change and record the differences. An example would be (if your current node is Editable poly):

    try destroyDialog selectVerts catch()
    rollout selectVerts ""
    (
        local verts, currentSel
    
        fn collectVerts event nodes =
        (
            local sel = polyop.getVertSelection $
            local newVerts = sel - currentSel
            local removedVerts = currentSel - sel
    
            for v in removedVerts do if (local index = findItem verts v) > 0 do deleteItem verts index
            for v in newVerts do append verts v
            currentSel = sel
        )
    
        local callback = nodeEventCallback mouseUp:on enabled:off subobjectSelectionChanged:collectVerts
    
        checkButton chbSwitchCallback "Select verts"
    
        on chbSwitchCallback changed state do
        (
            if state and isKindOf $ Editable_Poly then
            (
                verts = #()
                currentSel = polyop.getVertSelection $
                callback.enabled = on
            )
            else
            (
                callback.enabled = off
                print verts #noMap
            )
        )
    )
    createDialog selectVerts