Home Technical Talk
The BRAWL² Tournament Challenge has been announced!

It starts May 12, and ends Sept 12. Let's see what you got!

https://polycount.com/discussion/237047/the-brawl²-tournament

[Maxscript] How to get Selection count

polycounter lvl 18
Offline / Send Message
BeatKitano polycounter lvl 18
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
    Offline / Send Message
    Rick Stirling polycounter lvl 20
    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
    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
    1. (
    2. -- create a plane and convert it to Editable Poly
    3. local theNode = convertToPoly(Plane())
    4. -- get the Base Object of the plane node
    5. -- the first element at the bottom of the modifier stack
    6. -- in this case is not needed because there is only one item, but is a good practice
    7. -- in this case theBase is a pointer to the Editable Poly
    8. local theBase = theNode.baseObject
    9. -- set the selection at vert level to verts from 1 to 5 and from 10 to 17
    10. polyOp.setVertSelection theBase #{1..5, 10..17}
    11. -- get current vert selection
    12. -- baVertSelection is a type BitArray
    13. local baVertSelection = polyOp.getVertSelection theBase
    14. -- get the count of elements in baVertSelection BitArray
    15. local iVertSelectionCount = baVertSelection.numberSet
    16. -- print vert selection in the listener
    17. format "Current vert selection is: %, made by % elementsn" baVertSelection iVertSelectionCount
    18. -- Same goes for Edges and Faces
    19.  
    20. -- Edges
    21. polyOp.setEdgeSelection theBase #{6..9, 15..17, 20}
    22. local baEdgeSelection = polyOp.getEdgeSelection theBase
    23. local iEdgeSelectionCount = baEdgeSelection.numberSet
    24. format "Current edge selection is: %, made by % elementsn" baEdgeSelection iEdgeSelectionCount
    25.  
    26. -- Faces (Polys)
    27. polyOp.setFaceSelection theBase #{1..2, 7, 9..14}
    28. local baFaceSelection = polyOp.getFaceSelection theBase
    29. local iFaceSelectionCount = baFaceSelection.numberSet
    30.  
    31. format "Current face selection is: %, made by % elementsn" baFaceSelection iFaceSelectionCount
    32. )

    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
    Offline / Send Message
    MoP polycounter lvl 20
    Yeah, using the "numberSet" property of the bitarray is what I always do, it's pretty easy.
  • BeatKitano
    Offline / Send Message
    BeatKitano polycounter lvl 18
    Thank you so much SynchViewS, i searched all night yesterday, i can move on now :)
  • renderhjs
    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
    Offline / Send Message
    e-freak polycounter lvl 16
    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 :)
    1. global alledges = #{}
    2. addElement = false
    3. emptyedges = #{}
    4. alledges += polyop.getOpenEdges $.baseobject
    5. alledgesComp = alledges
    6. numberOfElements = 0;
    7. for i in alledges do (
    8. $.EditablePoly.SetSelection #Edge #{i}
    9. $.EditablePoly.ConvertSelection #Edge #Element
    10. $.EditablePoly.ConvertSelection #Element #Edge
    11. alledges -= polyOp.getEdgeSelection $.baseobject
    12. for i in (alledgesComp - alledges) do
    13. (
    14. addElement = true
    15. )
    16. if (addElement == true) do
    17. (
    18. numberOfElements += 1
    19. )
    20. addElement = false
    21. alledgesComp = alledges
    22. )
    23. format "%\n" numberOfElements
Sign In or Register to comment.