Announcement

Collapse
No announcement yet.

3dsMax scripting question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 3dsMax scripting question

    Hey guys,
    does anyone know a script that does the following:

    - take all the materials assigned to a scene
    - for each material, select the objects that have that material assigned
    - collapse them into a single mesh

    I tried my best to get something out of ChatGPT and the likes, but I only get some kind of pseudo-code.

    Sadly my knowledge of MaxScript is so bad I don't even know where to start from.
    https://www.behance.net/Oliver_Kossatz

  • #2
    I believe sini scripts has the ability to do that. Combine by material… I haven’t used it in a while but remember collapsing revit models into material groups that way. Which at the time was worth its weight in gold.

    Comment


    • #3
      Try this:
      Code:
      allMat = for m in scenematerials collect m
      for i=1 to allMat.count do (
      select (for j in objects where (j.material == allMat[i]) collect j)
      collapse.setDoBool false
      collapse.setOutputType #Mesh
      collapse.setCollapseTo #Single
      collapse.doCollapse $
      )​
      Aleksandar Hadzhiev | chaos.com
      Chaos Support Representative | contact us

      Comment


      • #4
        Thanks for the help!
        Unfortunately, I can not get this code to work as expected.
        Attached you will find a scene with some objects and 4 materials. When I run the code, some teapots will dissappear, but no objects are collapsed.

        mat_collapse.zip
        https://www.behance.net/Oliver_Kossatz

        Comment


        • #5
          Works fine on my end. Check the attached gif. Have I misunderstood you?
          Attached Files
          Aleksandar Hadzhiev | chaos.com
          Chaos Support Representative | contact us

          Comment


          • #6
            Hi Aleksandar,
            on your end it is working as expected indeed!
            Will try again, maybe I did something wrong.
            https://www.behance.net/Oliver_Kossatz

            Comment


            • #7
              Well,
              it is weird. On my end, nothing happens. But the listener is listing some errors:

              Code:
              #(01 - Default:Physical_Material, 02 - Default:Physical_Material, 04 - Default:Physical_Material, 03 - Default:Physical_Material)
              -- Error occurred in anonymous codeblock; filename: ; position: 256; line: 8
              -- Type error: Call needs function or class, got: OK
              -- MAXScript callstack:
              --    thread data: threadID:43856
              --    ------------------------------------------------------
              --    [stack level: 0]
              --    In i loop; filename: ; position: 257; line: 8
              --        Parameters:
              --            i: 1
              --        Locals:
              --            i: 1
              --            ​: undefined
              --        Externals:
              --            owner: undefined
              --    ------------------------------------------------------
              --    [stack level: 1]
              --    called from top-level
              
              ​
              I am on the latest version of 3dsMax 2025 if it help.s
              https://www.behance.net/Oliver_Kossatz

              Comment

              Working...
              X