Fix #1597. Prevent mixing objects on project creation.

This commit is contained in:
Dion Moult
2021-07-28 18:43:20 +10:00
parent 0596e2000c
commit d88c4fd377
@@ -36,10 +36,10 @@ class CreateProject(bpy.types.Operator):
bpy.ops.bim.add_person() bpy.ops.bim.add_person()
bpy.ops.bim.add_organisation() bpy.ops.bim.add_organisation()
project = bpy.data.objects.new("My Project", None) project = bpy.data.objects.new(self.get_name("IfcProject", "My Project"), None)
site = bpy.data.objects.new("My Site", None) site = bpy.data.objects.new(self.get_name("IfcSite", "My Site"), None)
building = bpy.data.objects.new("My Building", None) building = bpy.data.objects.new(self.get_name("IfcBuilding", "My Building"), None)
building_storey = bpy.data.objects.new("Ground Floor", None) building_storey = bpy.data.objects.new(self.get_name("IfcBuildingStorey", "My Storey"), None)
bpy.ops.bim.assign_class(obj=project.name, ifc_class="IfcProject") bpy.ops.bim.assign_class(obj=project.name, ifc_class="IfcProject")
bpy.ops.bim.assign_unit() bpy.ops.bim.assign_unit()
@@ -62,6 +62,14 @@ class CreateProject(bpy.types.Operator):
return {"FINISHED"} return {"FINISHED"}
def get_name(self, ifc_class, name):
if not bpy.data.objects.get(f"{ifc_class}/{name}"):
return name
i = 2
while bpy.data.objects.get(f"{ifc_class}/{name} {i}"):
i += 1
return f"{name} {i}"
def rollback(self, data): def rollback(self, data):
IfcStore.file = None IfcStore.file = None