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


              • #8
                Is the Collapse utility loaded on your end? Check the Plug-in Manager for the Utility.dlu. Check for typos, missing brackets, etc. Also try adding this line between line 3 and 4 and see if that makes any difference:
                Code:
                utilitypanel.openutility collapse
                Aleksandar Hadzhiev | chaos.com
                Chaos Support Representative | contact us

                Comment


                • #9
                  Thanks for the help.
                  Sadly I can not get this to work.
                  The script is still throwing errors while having no effect.
                  https://www.behance.net/Oliver_Kossatz

                  Comment


                  • #10
                    Try this:
                    Code:
                    (
                    local 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)
                    utilitypanel.openutility collapse
                    collapse.setDoBool false
                    collapse.setOutputType #Mesh
                    collapse.setCollapseTo #Single
                    collapse.doCollapse $
                    )
                    )​
                    Aleksandar Hadzhiev | chaos.com
                    Chaos Support Representative | contact us

                    Comment


                    • #11
                      Originally posted by kosso_olli View Post
                      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.

                      [ATTACH]n1211342[/ATTACH]
                      same here. objects disappear.
                      max 2024.
                      Marcin Piotrowski
                      youtube

                      Comment


                      • #12
                        Yeah, SINI has that in their suite of scripts. You can attach my layer, material, and selection. It is a priceless group of scripts.
                        Bobby Parker
                        www.bobby-parker.com
                        e-mail: info@bobby-parker.com
                        phone: 2188206812

                        My current hardware setup:
                        • Ryzen 9 5900x CPU
                        • 128gb Vengeance RGB Pro RAM
                        • NVIDIA GeForce RTX 4090
                        • ​Windows 11 Pro

                        Comment

                        Working...
                        X