mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
See #3069. Continued refactoring to not rely on users_collection[0].
This commit is contained in:
@@ -74,19 +74,8 @@ def name_callback(obj, data):
|
||||
element = IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id)
|
||||
if not element.is_a("IfcRoot"):
|
||||
return
|
||||
if element.is_a("IfcSpatialStructureElement") or (hasattr(element, "IsDecomposedBy") and element.IsDecomposedBy):
|
||||
collection = obj.users_collection[0]
|
||||
collection.name = obj.name
|
||||
if element.is_a("IfcGrid"):
|
||||
axis_obj = IfcStore.get_element(element.UAxes[0].id())
|
||||
axis_collection = axis_obj.users_collection[0]
|
||||
grid_collection = None
|
||||
for collection in bpy.data.collections:
|
||||
if axis_collection.name in collection.children.keys():
|
||||
grid_collection = collection
|
||||
break
|
||||
if grid_collection:
|
||||
grid_collection.name = obj.name
|
||||
if obj.BIMObjectProperties.collection:
|
||||
obj.BIMObjectProperties.collection.name = obj.name
|
||||
element.Name = "/".join(obj.name.split("/")[1:])
|
||||
refresh_ui_data()
|
||||
|
||||
|
||||
@@ -1330,7 +1330,7 @@ class IfcImporter:
|
||||
self.project = {"ifc": project}
|
||||
obj = tool.Ifc.get_object(project)
|
||||
if obj:
|
||||
self.project["blender"] = obj.users_collection[0]
|
||||
self.project["blender"] = obj.BIMObjectProperties.collection
|
||||
self.has_existing_project = True
|
||||
return
|
||||
self.project["blender"] = bpy.data.collections.new(
|
||||
@@ -1392,7 +1392,7 @@ class IfcImporter:
|
||||
obj = tool.Ifc.get_object(element)
|
||||
if obj:
|
||||
is_existing = True
|
||||
collection = obj.users_collection[0]
|
||||
collection = obj.BIMObjectProperties.collection
|
||||
self.collections[element.GlobalId] = collection
|
||||
if not is_existing:
|
||||
collection = bpy.data.collections.new(tool.Loader.get_name(element))
|
||||
|
||||
@@ -38,7 +38,7 @@ from blenderbim.bim.module.boundary.decorator import BoundaryDecorator
|
||||
|
||||
|
||||
def get_boundaries_collection(blender_space):
|
||||
space_collection = bpy.data.collections.get(blender_space.name, blender_space.users_collection[0])
|
||||
space_collection = blender_space.BIMObjectProperties.collection
|
||||
collection_name = f"Boundaries/{blender_space.BIMObjectProperties.ifc_definition_id}"
|
||||
boundaries_collection = space_collection.children.get(collection_name)
|
||||
if not boundaries_collection:
|
||||
|
||||
@@ -152,10 +152,18 @@ class DerivedPlacementsData:
|
||||
|
||||
@classmethod
|
||||
def load_collection(cls):
|
||||
cls.collection = bpy.data.objects.get(bpy.context.active_object.users_collection[0].name)
|
||||
cls.collection = None
|
||||
cls.collection_z = 0
|
||||
if cls.collection:
|
||||
cls.collection_z = cls.collection.matrix_world.translation.z
|
||||
element = tool.Ifc.get_entity(bpy.context.active_object)
|
||||
if not element:
|
||||
return
|
||||
parent = ifcopenshell.util.element.get_aggregate(element)
|
||||
if not parent:
|
||||
parent = ifcopenshell.util.element.get_container(element)
|
||||
if parent:
|
||||
cls.collection = tool.Ifc.get_object(parent)
|
||||
if cls.collection:
|
||||
cls.collection_z = cls.collection.matrix_world.translation.z
|
||||
|
||||
@classmethod
|
||||
def has_collection(cls):
|
||||
|
||||
@@ -30,32 +30,20 @@ def add_object(self, context):
|
||||
obj = bpy.data.objects.new("Grid", None)
|
||||
obj.name = "Grid"
|
||||
|
||||
collection = bpy.data.collections.new(obj.name)
|
||||
has_site_collection = False
|
||||
for child in context.view_layer.layer_collection.children:
|
||||
if "IfcProject/" not in child.name:
|
||||
continue
|
||||
for grandchild in child.children:
|
||||
if "IfcSite/" not in grandchild.name:
|
||||
continue
|
||||
has_site_collection = True
|
||||
grandchild.collection.children.link(collection)
|
||||
break
|
||||
if not has_site_collection:
|
||||
context.view_layer.active_layer_collection.collection.children.link(collection)
|
||||
collection = context.view_layer.active_layer_collection.collection
|
||||
site = tool.Ifc.get().by_type("IfcSite")
|
||||
if site:
|
||||
site = site[0]
|
||||
site_obj = tool.Ifc.get_object(site)
|
||||
if site_obj:
|
||||
collection = site_obj.BIMObjectProperties.collection or collection
|
||||
|
||||
collection.objects.link(obj)
|
||||
|
||||
self.file = IfcStore.get_file()
|
||||
if self.file:
|
||||
bpy.ops.bim.assign_class(obj=obj.name, ifc_class="IfcGrid")
|
||||
collection.name = obj.name
|
||||
grid = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
||||
if has_site_collection:
|
||||
site_obj = bpy.data.objects.get(grandchild.name)
|
||||
if site_obj and site_obj.BIMObjectProperties.ifc_definition_id:
|
||||
blenderbim.core.spatial.assign_container(
|
||||
tool.Ifc, tool.Collector, tool.Spatial, structure_obj=site_obj, element_obj=obj
|
||||
)
|
||||
bpy.ops.bim.assign_class(obj=obj.name, ifc_class="IfcGrid")
|
||||
grid = tool.Ifc.get_entity(obj)
|
||||
|
||||
collection = obj.BIMObjectProperties.collection or collection
|
||||
|
||||
axes_collection = bpy.data.collections.new("UAxes")
|
||||
collection.children.link(axes_collection)
|
||||
@@ -73,15 +61,14 @@ def add_object(self, context):
|
||||
|
||||
axes_collection.objects.link(obj)
|
||||
|
||||
if self.file:
|
||||
result = ifcopenshell.api.run(
|
||||
"grid.create_grid_axis",
|
||||
self.file,
|
||||
**{"axis_tag": tag, "uvw_axes": "UAxes", "grid": grid},
|
||||
)
|
||||
IfcStore.link_element(result, obj)
|
||||
ifcopenshell.api.run("grid.create_axis_curve", self.file, **{"axis_curve": obj, "grid_axis": result})
|
||||
obj.BIMObjectProperties.ifc_definition_id = result.id()
|
||||
result = ifcopenshell.api.run(
|
||||
"grid.create_grid_axis",
|
||||
tool.Ifc.get(),
|
||||
**{"axis_tag": tag, "uvw_axes": "UAxes", "grid": grid},
|
||||
)
|
||||
IfcStore.link_element(result, obj)
|
||||
ifcopenshell.api.run("grid.create_axis_curve", tool.Ifc.get(), **{"axis_curve": obj, "grid_axis": result})
|
||||
obj.BIMObjectProperties.ifc_definition_id = result.id()
|
||||
|
||||
axes_collection = bpy.data.collections.new("VAxes")
|
||||
collection.children.link(axes_collection)
|
||||
@@ -99,15 +86,14 @@ def add_object(self, context):
|
||||
|
||||
axes_collection.objects.link(obj)
|
||||
|
||||
if self.file:
|
||||
result = ifcopenshell.api.run(
|
||||
"grid.create_grid_axis",
|
||||
self.file,
|
||||
**{"axis_tag": tag, "uvw_axes": "VAxes", "grid": grid},
|
||||
)
|
||||
IfcStore.link_element(result, obj)
|
||||
ifcopenshell.api.run("grid.create_axis_curve", self.file, **{"axis_curve": obj, "grid_axis": result})
|
||||
obj.BIMObjectProperties.ifc_definition_id = result.id()
|
||||
result = ifcopenshell.api.run(
|
||||
"grid.create_grid_axis",
|
||||
tool.Ifc.get(),
|
||||
**{"axis_tag": tag, "uvw_axes": "VAxes", "grid": grid},
|
||||
)
|
||||
IfcStore.link_element(result, obj)
|
||||
ifcopenshell.api.run("grid.create_axis_curve", tool.Ifc.get(), **{"axis_curve": obj, "grid_axis": result})
|
||||
obj.BIMObjectProperties.ifc_definition_id = result.id()
|
||||
|
||||
|
||||
class BIM_OT_add_object(Operator):
|
||||
|
||||
@@ -51,13 +51,17 @@ class Collector(blenderbim.core.tool.Collector):
|
||||
|
||||
parent_collection = None
|
||||
|
||||
if obj.users_collection != (object_collection,) and obj.users_collection[0].name != obj.name:
|
||||
parent_collection = obj.users_collection[0]
|
||||
elif collection_collection and collection_collection.children.find(object_collection.name) == -1:
|
||||
for collection in bpy.data.collections:
|
||||
if collection.children.find(obj.users_collection[0].name) != -1:
|
||||
parent_collection = collection
|
||||
break
|
||||
for collection in obj.users_collection:
|
||||
if parent_collection:
|
||||
break
|
||||
if not collection.BIMCollectionProperties.obj:
|
||||
continue
|
||||
if collection.BIMCollectionProperties.obj == obj:
|
||||
for bpy_collection in bpy.data.collections:
|
||||
if bpy_collection.children.find(collection.name) != -1:
|
||||
parent_collection = bpy_collection
|
||||
else:
|
||||
parent_collection = collection
|
||||
|
||||
if not parent_collection:
|
||||
return
|
||||
@@ -214,7 +218,7 @@ class Collector(blenderbim.core.tool.Collector):
|
||||
if not collection:
|
||||
collection = bpy.data.collections.new(name)
|
||||
project_obj = tool.Ifc.get_object(tool.Ifc.get().by_type("IfcProject")[0])
|
||||
project_obj.users_collection[0].children.link(collection)
|
||||
project_obj.BIMObjectProperties.collection.children.link(collection)
|
||||
return collection
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -113,7 +113,8 @@ class Misc(blenderbim.core.tool.Misc):
|
||||
new_obj = obj.copy()
|
||||
new_obj.data = obj.data.copy()
|
||||
|
||||
obj.users_collection[0].objects.link(new_obj)
|
||||
for collection in obj.users_collection:
|
||||
collection.objects.link(new_obj)
|
||||
|
||||
mod = new_obj.modifiers.new(type="BOOLEAN", name="Boolean")
|
||||
mod.object = cutter
|
||||
|
||||
@@ -104,7 +104,7 @@ class Project(blenderbim.core.tool.Project):
|
||||
|
||||
@classmethod
|
||||
def set_active_spatial_element(cls, obj):
|
||||
collection = obj.users_collection[0]
|
||||
collection = obj.BIMObjectProperties.collection
|
||||
queue = [bpy.context.view_layer.layer_collection]
|
||||
layer_collection = None
|
||||
|
||||
|
||||
@@ -331,6 +331,8 @@ class TestSync(NewFile):
|
||||
bpy.ops.bim.create_project()
|
||||
obj = bpy.data.objects.new("IfcBuildingStorey/Name", None)
|
||||
col = bpy.data.collections.new("IfcBuildingStorey/Name")
|
||||
obj.BIMObjectProperties.collection = col
|
||||
col.BIMCollectionProperties.obj = obj
|
||||
element = tool.Ifc.get().createIfcBuildingStorey(Name="Name")
|
||||
tool.Ifc.link(element, obj)
|
||||
bpy.data.collections.get("IfcBuilding/My Building").children.link(col)
|
||||
|
||||
Reference in New Issue
Block a user