Announcement

Collapse
No announcement yet.

Script to delete duplicate objects

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

  • Script to delete duplicate objects

    A couple CAD files I need to use have between 16k and 20k objects in them. Hundreds (maybe thousands) of these objects are duplicate instances that I don't need, and cause rendering problems. So I need a script that will delete duplicate instances of objects. However, to make sure all my nuts and bolts remain, the script would only delete the extra objects that have the same pivot point.

    I found a couple threads on Scriptspot regarding this sort of situation, but they don't seem to work for me for some reason. Perhaps one of you can help?

    Thanks!
    - Geoff

  • #2
    How do all your objects come in? Are they editable mesh files? It'd be possible to process a file and group objects by pivot first and then run a second pass to check things like vert counts to match up better but it's the type of thing that'd run for ages!

    Comment


    • #3
      They're STEP files, so they come in as Editable Meshes (because I set the importer to do that) rather than Body Objects. Fortunately the new importer retains instancing info, so all these duplicates are instances. So I'm sure a script can use that to its advantage. It would probably be doable by hand if the objects had proper names, but most of these objects have the exact same names as hundreds of other objects.
      - Geoff

      Comment


      • #4
        How do you tell if they're a copy? Same name? Same position? What's the common denominator?
        Gavin Greenwalt
        im.thatoneguy[at]gmail.com || Gavin[at]SFStudios.com
        Straightface Studios

        Comment


        • #5
          I guess what the script would need to do is:

          • Test object to see if there are any instances
          • If no: move on to next object
          • If yes: do the instances share the same pivot point?
          • If yes: delete (only) those instances
          • If no: leave those instances alone.
          Last edited by YoyoBoy; 01-10-2015, 03:47 PM.
          - Geoff

          Comment


          • #6
            Code:
            disablesceneredraw()
            
            for o in objects do
            (
               for p in (InstanceMgr.GetInstances o &instances) where (p != o && p.position == o.position) do
               (
                  try(delete p)catch()
               )
            )
            
            enablesceneredraw()
            This is completely untested I just wrote this down in the post and don't have max. I would save before running it obviously.
            Gavin Greenwalt
            im.thatoneguy[at]gmail.com || Gavin[at]SFStudios.com
            Straightface Studios

            Comment


            • #7
              Thanks, Gavin!

              I'm getting an error though: --No *map* function for 6
              - Geoff

              Comment


              • #8
                Code:
                disablesceneredraw()
                
                for o in objects do
                (
                   InstanceMgr.GetInstances o &instances
                   for p in instances where (p != o && p.position == o.position) do
                   (
                      try(delete p)catch()
                   )
                )
                
                enablesceneredraw()
                Last edited by im.thatoneguy; 01-10-2015, 11:22 PM.
                Gavin Greenwalt
                im.thatoneguy[at]gmail.com || Gavin[at]SFStudios.com
                Straightface Studios

                Comment


                • #9
                  Thanks again.

                  That gives me a different error.

                  --Type error: Call needs function or class, got:
                  $Editable_Mesh:object name @ coordinates

                  In case it's relevant, the object name is "INLET/OUTLET Cut-Extrude1"
                  And the coordinates are 0.000000, -250.399536, 39.852600
                  - Geoff

                  Comment


                  • #10
                    Is it possible for characters in the names of objects to cause problems with scripts? Like slashes and such? I just noticed that there are some objects in the scene with names that start with a space. And others have brackets and parentheses, etc.
                    Last edited by YoyoBoy; 02-10-2015, 07:03 AM.
                    - Geoff

                    Comment


                    • #11
                      Update!

                      Someone on the area gave me this script and it works!

                      Code:
                      collected = #()
                      
                      for obj1 in objects where findItem collected obj1 == 0 do
                      	for obj2 in objects where obj2.baseObject == obj1.baseObject AND obj1 != obj2 AND distance obj1 obj2 < 1e-3 do
                      		append collected obj2
                      
                      delete collected
                      - Geoff

                      Comment

                      Working...
                      X