Search code examples
pythonalgorithmcombinationsmaxscript

Combinations of group items, no repeating


I have items in 3 groups and I want to generate arrays like the following example:

Group 1 = {m1, m2, m3}
Group 2 = {m4, m5}
Group 3 = {m6, m7, m8, m9}

{m1, m4, m6}
{m2, m5, m7}
{m3, null, m8}
{null, null, m9}

Every element of the groups should only appear once in the generated arrays. How should I approach this problem?


Solution

  • This is how I did it, its maxscript code which analyze multi-material that can have others multi-materials, and creates new materials from each ID. Maybe I was bit unclear in the first queastion sorry about that.

        local maxSubID = amax arrayNumSubs --it is the count of the array with highest number of items.
    
    
        for maxSubCounter = 1 to maxSubID do
        (
            tmpMat = multimaterial numsubs:mainMatIDs
            for subCounter = 1 to mainMatIDs do
            (
                if (rootMat[subCounter] != undefined) then
                (
                    tmpMat[subCounter] = rootMat[subCounter][maxSubCounter]
                )else
                (
                    tmpMat[subCounter] = undefined
                )
            )
            append materialsToApply tmpMat
        )