mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 11:42:45 +00:00
Objects now sync spatial hierarchy more robustly on export, and clean the collection tree in case the user messed it up.
This commit is contained in:
@@ -24,6 +24,45 @@ import blenderbim.tool as tool
|
||||
|
||||
|
||||
class Collector(blenderbim.core.tool.Collector):
|
||||
@classmethod
|
||||
def sync(cls, obj):
|
||||
# This is the reverse of assign. It reads the Blender collection and figures out its IFC hierarchy
|
||||
element = tool.Ifc.get_entity(obj)
|
||||
|
||||
if element.is_a("IfcProject") or element.is_a("IfcGridAxis"):
|
||||
return
|
||||
|
||||
object_collection = None
|
||||
collection_collection = None
|
||||
|
||||
object_collection = cls._get_own_collection(element, obj)
|
||||
if object_collection:
|
||||
collection_collection = cls._get_collection(element, obj)
|
||||
else:
|
||||
object_collection = cls._get_collection(element, obj)
|
||||
|
||||
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
|
||||
|
||||
if parent_collection:
|
||||
parent_obj = bpy.data.objects.get(parent_collection.name)
|
||||
parent = tool.Ifc.get_entity(parent_obj)
|
||||
if parent:
|
||||
# This is lazy, but works. One of these will succeed, the other will fail silently.
|
||||
blenderbim.core.spatial.assign_container(
|
||||
tool.Ifc, tool.Collector, tool.Spatial, structure_obj=parent_obj, element_obj=obj
|
||||
)
|
||||
blenderbim.core.aggregate.assign_object(
|
||||
tool.Ifc, tool.Aggregate, tool.Collector, relating_obj=parent_obj, related_obj=obj
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def assign(cls, obj):
|
||||
element = tool.Ifc.get_entity(obj)
|
||||
|
||||
Reference in New Issue
Block a user