- from .scene import create_scene_from_current
- scene = create_scene_from_current(context, selected_only=self.selected_only, visible_only=self.visible_only)
-
- path, base = os.path.split(out_fn)
- base, ext = os.path.splitext(base)
-
- export_names = {}
- used_names = set()
- for p in scene.prototypes:
- clones = [i for i in scene.instances if i.prototype==p.name]
-
- prefix = p.name
- for c in clones:
- while not c.name.startswith(prefix):
- pos = max(prefix.rfind(' '), prefix.rfind('.'))
- if pos<0:
- break;
- prefix = prefix[:pos]
-
- if prefix:
- export_names[p.name+".object"] = prefix.strip(" .")
- else:
- used_names.add(p.name)
-
- 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)
-