mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 22:11:36 +00:00
wip: DuplicateMoveAggregate now calls DuplicateMove function and removes code duplication
This commit is contained in:
@@ -819,6 +819,7 @@ class OverrideDuplicateMove(bpy.types.Operator):
|
|||||||
# Recreate decompositions
|
# Recreate decompositions
|
||||||
tool.Root.recreate_decompositions(relationships, old_to_new)
|
tool.Root.recreate_decompositions(relationships, old_to_new)
|
||||||
blenderbim.bim.handler.refresh_ui_data()
|
blenderbim.bim.handler.refresh_ui_data()
|
||||||
|
return old_to_new
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def process_arrays(self, context):
|
def process_arrays(self, context):
|
||||||
@@ -904,6 +905,8 @@ class OverrideDuplicateMoveAggregate(bpy.types.Operator):
|
|||||||
|
|
||||||
### Adding the assembly data
|
### Adding the assembly data
|
||||||
def add_assembly_data(element, parent, data_to_add):
|
def add_assembly_data(element, parent, data_to_add):
|
||||||
|
obj = tool.Ifc.get_object(element)
|
||||||
|
obj.select_set(True)
|
||||||
pset = ifcopenshell.util.element.get_pset(element, "BBIM_Aggregate_Data")
|
pset = ifcopenshell.util.element.get_pset(element, "BBIM_Aggregate_Data")
|
||||||
data = [data_to_add]
|
data = [data_to_add]
|
||||||
|
|
||||||
@@ -935,30 +938,14 @@ class OverrideDuplicateMoveAggregate(bpy.types.Operator):
|
|||||||
properties={"Parent": parent.GlobalId, "Data": json.dumps(data)},
|
properties={"Parent": parent.GlobalId, "Data": json.dumps(data)},
|
||||||
)
|
)
|
||||||
|
|
||||||
def add_child_to_assembly_data(new_entity):
|
|
||||||
pset = ifcopenshell.util.element.get_pset(new_entity, "BBIM_Aggregate_Data")
|
|
||||||
parent_element = tool.Ifc.get().by_guid(pset["Parent"])
|
|
||||||
parent_pset = ifcopenshell.util.element.get_pset(parent_element, "BBIM_Aggregate_Data")
|
|
||||||
data = json.loads(parent_pset["Data"])
|
|
||||||
data[0]["children"].append(new_entity.GlobalId)
|
|
||||||
|
|
||||||
ifcopenshell.api.run(
|
|
||||||
"pset.edit_pset",
|
|
||||||
tool.Ifc.get(),
|
|
||||||
pset=tool.Ifc.get().by_id(parent_pset["id"]),
|
|
||||||
properties={"Data": json.dumps(data)},
|
|
||||||
)
|
|
||||||
|
|
||||||
def create_data_structure(entity, level=-1):
|
def create_data_structure(entity, level=-1):
|
||||||
level += 1
|
level += 1
|
||||||
|
|
||||||
data_children = {
|
data_children = {
|
||||||
"children": [],
|
|
||||||
"instance_of": [],
|
"instance_of": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
data_parent = {
|
data_parent = {
|
||||||
"children": [],
|
|
||||||
"instance_of": [entity.GlobalId],
|
"instance_of": [entity.GlobalId],
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -973,11 +960,9 @@ class OverrideDuplicateMoveAggregate(bpy.types.Operator):
|
|||||||
for part in parts:
|
for part in parts:
|
||||||
if part.is_a("IfcElementAssembly"):
|
if part.is_a("IfcElementAssembly"):
|
||||||
add_assembly_data(part, entity, data_children)
|
add_assembly_data(part, entity, data_children)
|
||||||
add_child_to_assembly_data(part)
|
|
||||||
create_data_structure(part, level)
|
create_data_structure(part, level)
|
||||||
continue
|
continue
|
||||||
add_assembly_data(part, entity, data_children)
|
add_assembly_data(part, entity, data_children)
|
||||||
add_child_to_assembly_data(part)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -1112,41 +1097,37 @@ class OverrideDuplicateMoveAggregate(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
selected_obj = context.selected_objects[0]
|
selected_obj = context.selected_objects[0]
|
||||||
selected_root_entity = tool.Ifc.get_entity(selected_obj)
|
selected_element = tool.Ifc.get_entity(selected_obj)
|
||||||
|
|
||||||
if not selected_root_entity.is_a("IfcElementAssembly"):
|
if selected_element.is_a("IfcElementAssembly"):
|
||||||
|
pass
|
||||||
|
elif selected_element.Decomposes:
|
||||||
|
if selected_element.Decomposes[0].RelatingObject.is_a("IfcElementAssembly"):
|
||||||
|
selected_element = selected_element.Decomposes[0].RelatingObject
|
||||||
|
selected_obj = tool.Ifc.get_object(selected_element)
|
||||||
|
else:
|
||||||
|
self.report({"INFO"}, "Object is not part of a IfcElementAssembly.")
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
pset = ifcopenshell.util.element.get_pset(selected_root_entity, "BBIM_Aggregate_Data")
|
pset = ifcopenshell.util.element.get_pset(selected_element, "BBIM_Aggregate_Data")
|
||||||
if not pset:
|
if not pset:
|
||||||
create_data_structure(selected_root_entity)
|
create_data_structure(selected_element)
|
||||||
|
|
||||||
pset = ifcopenshell.util.element.get_pset(selected_root_entity, "BBIM_Aggregate_Data")
|
old_to_new = OverrideDuplicateMove.execute_ifc_duplicate_operator(self, context, linked=True)
|
||||||
|
|
||||||
selected_root_parent = selected_root_entity
|
for old_element, new_element in old_to_new.items():
|
||||||
|
print(old_element, new_element)
|
||||||
new_root_entity = duplicate_all(selected_obj)
|
old_parent = ifcopenshell.util.element.get_aggregate(old_element)
|
||||||
|
if old_parent:
|
||||||
recreate_data_structure(new_root_entity)
|
new_parent = old_to_new[old_parent]
|
||||||
|
print(new_parent)
|
||||||
# Remove connections with old objects
|
blenderbim.core.aggregate.assign_object(
|
||||||
for new in old_to_new.values():
|
tool.Ifc,
|
||||||
for connection in new[0].ConnectedTo:
|
tool.Aggregate,
|
||||||
entity = connection.RelatedElement
|
tool.Collector,
|
||||||
if entity in old_to_new.keys():
|
relating_obj=tool.Ifc.get_object(new_parent[0]),
|
||||||
core.remove_connection(tool.Geometry, connection=connection)
|
related_obj=tool.Ifc.get_object(new_element[0]),
|
||||||
for connection in new[0].ConnectedFrom:
|
)
|
||||||
entity = connection.RelatingElement
|
|
||||||
if entity in old_to_new.keys():
|
|
||||||
core.remove_connection(tool.Geometry, connection=connection)
|
|
||||||
|
|
||||||
old_objs = []
|
|
||||||
for old, new in old_to_new.items():
|
|
||||||
old_objs.append(tool.Ifc.get_object(old))
|
|
||||||
|
|
||||||
relationships = tool.Root.get_decomposition_relationships(old_objs)
|
|
||||||
|
|
||||||
tool.Root.recreate_decompositions(relationships, old_to_new)
|
|
||||||
|
|
||||||
blenderbim.bim.handler.refresh_ui_data()
|
blenderbim.bim.handler.refresh_ui_data()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user