]> git.tdb.fi Git - libs/gl.git/commitdiff
Ensure that objects have unique names while exporting a scene
authorMikko Rasa <tdb@tdb.fi>
Tue, 13 Apr 2021 09:02:24 +0000 (12:02 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 13 Apr 2021 09:02:24 +0000 (12:02 +0300)
blender/io_mspgl/export_scene.py

index 18cdcbca2404cea30f14b89f863e9aecef512c38..2ec85ccbddbdef3ed708ddae330d5b713fb98bea 100644 (file)
@@ -30,6 +30,7 @@ class SceneExporter:
                object_prototypes = {}
                unique_objects = []
                export_names = {}
+               used_names = set()
                for o in objs:
                        if o.name in object_prototypes:
                                continue
@@ -54,12 +55,23 @@ class SceneExporter:
                                        prefix = prefix[:pos]
 
                        if prefix:
-                               export_names[o.name+".object"] = prefix.strip(" .")+".object"
+                               export_names[o.name+".object"] = prefix.strip(" .")
+                       else:
+                               used_names.add(o.name)
 
                        unique_objects.append(o)
                        for c in clones:
                                object_prototypes[c.name] = o
 
+               for n, e in export_names.items():
+                       if e in used_names:
+                               number = 1
+                               while "{}_{}".format(e, number) in used_names:
+                                       number += 1
+                               e += "_{}".format(number)
+                       export_names[n] = e+".object"
+                       used_names.add(e)
+
                from .util import Progress
                progress = Progress(self.show_progress and context)