Home Technical Talk

[Maxscript] How to get Selection count

polycounter lvl 16
Offline / Send Message
BeatKitano polycounter lvl 16
i'm slowly converting to max, but want some customization in the toolset, and i encountered a wall.

I'm really just discovering maxscript and i can't find a way to get the sub object selection count in editable poly.
It's really frustrating because the values are given in the modifier tab :/

Can you help me ?



Thanx.

Replies

  • Rick Stirling
    Options
    Offline / Send Message
    Rick Stirling polycounter lvl 18
    I don't have max at home, but I've done something similar before by looping though all the faces in the object and using getElementsUsingFace to get an array of all the faces in each element.
  • SyncViewS
    Options
    Offline / Send Message
    SyncViewS polycounter lvl 13
    Hi, here is a sample of the command you need. Here is a small index of handy bookmarks in the MaxScript reference:

    Nodes:
    - Node Common Properties, Operators, and Methods

    Editable Poly Stuff:
    - Interface: EditablePoly
    - Editable_Poly Methods

    Array and BitArray
    - Array Values
    - BitArray Values
    (
        -- create a plane and convert it to Editable Poly
        local theNode = convertToPoly(Plane())
        
        -- get the Base Object of the plane node
        -- the first element at the bottom of the modifier stack
        -- in this case is not needed because there is only one item, but is a good practice
        -- in this case theBase is a pointer to the Editable Poly 
        local theBase = theNode.baseObject
        
        -- set the selection at vert level to verts from 1 to 5 and from 10 to 17
        polyOp.setVertSelection theBase #{1..5, 10..17}
        
        -- get current vert selection
        -- baVertSelection is a type BitArray
        local baVertSelection = polyOp.getVertSelection theBase
        
        -- get the count of elements in baVertSelection BitArray
        local iVertSelectionCount = baVertSelection.numberSet
        
        -- print vert selection in the listener
        format "Current vert selection is: %, made by % elementsn" baVertSelection iVertSelectionCount
        
        -- Same goes for Edges and Faces 
    
        -- Edges
        polyOp.setEdgeSelection theBase #{6..9, 15..17, 20}
        local baEdgeSelection = polyOp.getEdgeSelection theBase
        local iEdgeSelectionCount = baEdgeSelection.numberSet
     
        format "Current edge selection is: %, made by % elementsn" baEdgeSelection iEdgeSelectionCount
    
        -- Faces (Polys)
        polyOp.setFaceSelection theBase #{1..2, 7, 9..14}
        local baFaceSelection = polyOp.getFaceSelection theBase 
        local iFaceSelectionCount = baFaceSelection.numberSet
    
        format "Current face selection is: %, made by % elementsn" baFaceSelection iFaceSelectionCount
    )
    

    Edit Note: elementsn should be elementsBACKSLASHn to jump to a new line. The html eats it away.

    Press F11 to open the MaxScript listener. After the execution of this code you can select the plane and by cycling through sub-object levels, verify the actual selections.
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    Yeah, using the "numberSet" property of the bitarray is what I always do, it's pretty easy.
  • BeatKitano
    Options
    Offline / Send Message
    BeatKitano polycounter lvl 16
    Thank you so much SynchViewS, i searched all night yesterday, i can move on now :)
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    he he more people are converting to maxScript which is certainly good for the tech talk section here at polycount.
  • e-freak
    Options
    Offline / Send Message
    Sorry for resurecting this old thread, but I'm stuck with a similar problem:LzMcM.jpg

    I need Max to return the number of Elements/SubObjects (4 in this test case). I tried getOpenEdges and converting these to FaceSelections and reading those but I'm stuck now comparing these to get the number of Elements.

    Am I on the right track and how could this comparison work or is there an easier way to do this? (why is there no getNumElements :( )


    Edit: I think I got it, have to test it though:
    Create a bitArray with all open Edges
    Select the first Edge
    Set NumberOfElements +1
    Convert to Element Selection
    Convert to Edge Selection
    Subtract those Edges from the bitArray
    Select the next Edge and loop.

    Edit: It worked :)
    global alledges = #{}
    addElement = false
    emptyedges = #{}
    alledges += polyop.getOpenEdges $.baseobject
    alledgesComp = alledges
    numberOfElements = 0;
    for i in alledges do (
    $.EditablePoly.SetSelection #Edge #{i}
    $.EditablePoly.ConvertSelection #Edge #Element
    $.EditablePoly.ConvertSelection #Element #Edge
    alledges -= polyOp.getEdgeSelection $.baseobject
        for i in (alledgesComp - alledges) do
        (
            addElement = true
        )
        if (addElement == true)  do
        (
            numberOfElements += 1
        )
        addElement = false
    alledgesComp = alledges
    )
    format "%\n" numberOfElements
    
Sign In or Register to comment.