Home Technical Talk

[MaxScript] store elements into array problems

polycounter lvl 7
Offline / Send Message
EspiSensei polycounter lvl 7
Hi everyone!

i'm going to try a script create a dummie into each epoly element, i've try some ways but i dont get to store the Unique elements into Array, i've got to save every elements by face but i dont get to delete duplicated elements, its a array with BitArrays.

I know this question is very noob :sweat:

Thanks !!

Replies

  • poopipe
    Offline / Send Message
    poopipe grand marshal polycounter
    can you explain what you're doing in a bit more detail ? - I can't see how you'd end up with any duplicates if you simply store a face selection bit array for each element 
  • EspiSensei
    Offline / Send Message
    EspiSensei polycounter lvl 7
    Sorry Poopipe, here the code:

    fn selectElements tObject= (
    local totalFaces= polyop.getNumFaces tObject
    local allFaceElements = #()
    local uniqueElements = #()



    for i=1 to totalFaces do ( -- get all Elements
    objElement = polyop.getElementsUsingFace tObject #(i) -- return a BitArray by default
    append allFaceElements objElement
    )

    for FaceElement in allFaceElements do( -- search and destroy all duplicated bitArrays
    print (FaceElement[1] as string)
    if uniqueElements.count > 0 then (
    for FaceElement in allFaceElements do(
    id = findItem uniqueElements FaceElement
    if (id == 0) then (append uniqueElements FaceElement)
    )
    )
    )

    selectElements $
    ------------------------------------------------------------------------------------------------------
    Maybe i'm going for bad way.
    how can i do that you say ?
  • poopipe
    Offline / Send Message
    poopipe grand marshal polycounter
    I see the problem now  - 

    Rather than automatically appending in the first for loop you should check if the current face is present in any of the existing bitarrays in allFaceElements - if it is,  you don't need to bother with it. 

    that way you should end up with unique list of bitarrays
  • EspiSensei
    Offline / Send Message
    EspiSensei polycounter lvl 7
    Ok! i got it!
    i'll try to do that!

    thank so much! ;)
  • miauu
    Offline / Send Message
    miauu polycounter lvl 14


    (&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; function SelectElements obj =<br>&nbsp;&nbsp;&nbsp; (<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local poGetElementsUsingFace = polyop.getElementsUsingFace<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; elementsArr = #()<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; objFacesBA = #{1..(polyop.getNumFaces obj)}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while not objFacesBA.isEmpty do<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; faceIdx = (objFacesBA as array)[1]<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; objElementBA = poGetElementsUsingFace obj #(faceIdx)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; append elementsArr objElementBA<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; objFacesBA -= objElementBA<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; )<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; elementsArr<br>&nbsp;&nbsp;&nbsp; )<br><br>&nbsp;&nbsp;&nbsp; uniqueElementsArr = SelectElements $<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; print uniqueElementsArr<br>)







  • EspiSensei
    Offline / Send Message
    EspiSensei polycounter lvl 7
    Thats better that my way!, you rock miauu!

    thank you so much! ^^
  • miauu
    Offline / Send Message
    miauu polycounter lvl 14
    Thank you.
    Finally i have found how to post the code as a code. :)


  • EspiSensei
    Offline / Send Message
    EspiSensei polycounter lvl 7
    jajaja, how does it do that? 
  • monster
    Offline / Send Message
    monster polycounter
    The "Format" button, next to the smiley face, has a code option.
Sign In or Register to comment.