mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-10 06:00:51 +00:00
black format
This commit is contained in:
@@ -908,7 +908,7 @@ class OverrideDuplicateMove(bpy.types.Operator):
|
|||||||
if parts:
|
if parts:
|
||||||
index = DuplicateMoveLinkedAggregate.get_max_index(parts)
|
index = DuplicateMoveLinkedAggregate.get_max_index(parts)
|
||||||
index += 1
|
index += 1
|
||||||
pset = tool.Ifc.get().by_id(pset['id'])
|
pset = tool.Ifc.get().by_id(pset["id"])
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"pset.edit_pset",
|
"pset.edit_pset",
|
||||||
tool.Ifc.get(),
|
tool.Ifc.get(),
|
||||||
@@ -976,26 +976,23 @@ class DuplicateMoveLinkedAggregate(bpy.types.Operator):
|
|||||||
if parts:
|
if parts:
|
||||||
index = DuplicateMoveLinkedAggregate.get_max_index(parts)
|
index = DuplicateMoveLinkedAggregate.get_max_index(parts)
|
||||||
add_linked_aggregate_pset(element, index)
|
add_linked_aggregate_pset(element, index)
|
||||||
index +=1
|
index += 1
|
||||||
for part in parts:
|
for part in parts:
|
||||||
if part.is_a("IfcElementAssembly"):
|
if part.is_a("IfcElementAssembly"):
|
||||||
select_objects_and_add_data(part)
|
select_objects_and_add_data(part)
|
||||||
else:
|
else:
|
||||||
add_linked_aggregate_pset(part, index)
|
add_linked_aggregate_pset(part, index)
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
obj = tool.Ifc.get_object(part)
|
obj = tool.Ifc.get_object(part)
|
||||||
obj.select_set(True)
|
obj.select_set(True)
|
||||||
|
|
||||||
|
|
||||||
def add_linked_aggregate_pset(part, index):
|
def add_linked_aggregate_pset(part, index):
|
||||||
pset = ifcopenshell.util.element.get_pset(part, self.pset_name)
|
pset = ifcopenshell.util.element.get_pset(part, self.pset_name)
|
||||||
|
|
||||||
if not pset:
|
if not pset:
|
||||||
pset = ifcopenshell.api.run(
|
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=part, name=self.pset_name)
|
||||||
"pset.add_pset", tool.Ifc.get(), product=part, name=self.pset_name
|
|
||||||
)
|
|
||||||
|
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"pset.edit_pset",
|
"pset.edit_pset",
|
||||||
tool.Ifc.get(),
|
tool.Ifc.get(),
|
||||||
@@ -1029,21 +1026,20 @@ class DuplicateMoveLinkedAggregate(bpy.types.Operator):
|
|||||||
if r.is_a("IfcRelAssignsToGroup")
|
if r.is_a("IfcRelAssignsToGroup")
|
||||||
if "BBIM_Linked_Aggregate" in r.RelatingGroup.Name
|
if "BBIM_Linked_Aggregate" in r.RelatingGroup.Name
|
||||||
][0]
|
][0]
|
||||||
|
|
||||||
number = len(group_elements) - 1
|
number = len(group_elements) - 1
|
||||||
number = f"{number:02d}"
|
number = f"{number:02d}"
|
||||||
new_obj = tool.Ifc.get_object(new[0])
|
new_obj = tool.Ifc.get_object(new[0])
|
||||||
pattern1 = r'_\d'
|
pattern1 = r"_\d"
|
||||||
if re.findall(pattern1, new_obj.name):
|
if re.findall(pattern1, new_obj.name):
|
||||||
split_name = new_obj.name.split("_")
|
split_name = new_obj.name.split("_")
|
||||||
new_obj.name = split_name[0] + "_" + number
|
new_obj.name = split_name[0] + "_" + number
|
||||||
continue
|
continue
|
||||||
pattern2 = r'\.\d{3}'
|
pattern2 = r"\.\d{3}"
|
||||||
if re.findall(pattern2, new_obj.name):
|
if re.findall(pattern2, new_obj.name):
|
||||||
split_name = new_obj.name.split(".")
|
split_name = new_obj.name.split(".")
|
||||||
new_obj.name = split_name[0] + "_" + number
|
new_obj.name = split_name[0] + "_" + number
|
||||||
|
|
||||||
|
|
||||||
if len(context.selected_objects) != 1:
|
if len(context.selected_objects) != 1:
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
@@ -1065,7 +1061,7 @@ class DuplicateMoveLinkedAggregate(bpy.types.Operator):
|
|||||||
old_to_new = OverrideDuplicateMove.execute_ifc_duplicate_operator(self, context, linked=True)
|
old_to_new = OverrideDuplicateMove.execute_ifc_duplicate_operator(self, context, linked=True)
|
||||||
|
|
||||||
custom_incremental_naming_for_element_assembly(old_to_new)
|
custom_incremental_naming_for_element_assembly(old_to_new)
|
||||||
|
|
||||||
# Recreate aggregate relationship
|
# Recreate aggregate relationship
|
||||||
for old in old_to_new.keys():
|
for old in old_to_new.keys():
|
||||||
if old.is_a("IfcElementAssembly"):
|
if old.is_a("IfcElementAssembly"):
|
||||||
@@ -1075,17 +1071,15 @@ class DuplicateMoveLinkedAggregate(bpy.types.Operator):
|
|||||||
|
|
||||||
return old_to_new
|
return old_to_new
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_max_index(parts):
|
def get_max_index(parts):
|
||||||
psets = [ifcopenshell.util.element.get_pset(p, "BBIM_Linked_Aggregate") for p in parts]
|
psets = [ifcopenshell.util.element.get_pset(p, "BBIM_Linked_Aggregate") for p in parts]
|
||||||
index = [i['Index'] for i in psets if i]
|
index = [i["Index"] for i in psets if i]
|
||||||
if len(index) > 0:
|
if len(index) > 0:
|
||||||
index = max(index)
|
index = max(index)
|
||||||
return index
|
return index
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RefreshLinkedAggregate(bpy.types.Operator):
|
class RefreshLinkedAggregate(bpy.types.Operator):
|
||||||
@@ -1134,9 +1128,9 @@ class RefreshLinkedAggregate(bpy.types.Operator):
|
|||||||
original_names[group] = {}
|
original_names[group] = {}
|
||||||
|
|
||||||
pset = ifcopenshell.util.element.get_pset(element, self.pset_name)
|
pset = ifcopenshell.util.element.get_pset(element, self.pset_name)
|
||||||
index = pset['Index']
|
index = pset["Index"]
|
||||||
original_names[group][index] = tool.Ifc.get_object(element).name
|
original_names[group][index] = tool.Ifc.get_object(element).name
|
||||||
|
|
||||||
parts = ifcopenshell.util.element.get_parts(element)
|
parts = ifcopenshell.util.element.get_parts(element)
|
||||||
if parts:
|
if parts:
|
||||||
for part in parts:
|
for part in parts:
|
||||||
@@ -1144,20 +1138,22 @@ class RefreshLinkedAggregate(bpy.types.Operator):
|
|||||||
original_names | get_original_names(part)
|
original_names | get_original_names(part)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
pset = ifcopenshell.util.element.get_pset(part, self.pset_name)
|
pset = ifcopenshell.util.element.get_pset(part, self.pset_name)
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
index = pset['Index']
|
index = pset["Index"]
|
||||||
original_names[group][index] = tool.Ifc.get_object(part).name
|
original_names[group][index] = tool.Ifc.get_object(part).name
|
||||||
|
|
||||||
return original_names
|
return original_names
|
||||||
|
|
||||||
def set_original_name(obj, original_names):
|
def set_original_name(obj, original_names):
|
||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
aggregate = ifcopenshell.util.element.get_aggregate(element)
|
aggregate = ifcopenshell.util.element.get_aggregate(element)
|
||||||
if ifcopenshell.util.element.get_parts(element): # if element has parts it means it is the base of and aggregate or sub-aggregate
|
if ifcopenshell.util.element.get_parts(
|
||||||
|
element
|
||||||
|
): # if element has parts it means it is the base of and aggregate or sub-aggregate
|
||||||
aggregate = element
|
aggregate = element
|
||||||
|
|
||||||
group = [
|
group = [
|
||||||
r.RelatingGroup
|
r.RelatingGroup
|
||||||
for r in getattr(aggregate, "HasAssignments", []) or []
|
for r in getattr(aggregate, "HasAssignments", []) or []
|
||||||
@@ -1166,18 +1162,16 @@ class RefreshLinkedAggregate(bpy.types.Operator):
|
|||||||
]
|
]
|
||||||
if not group:
|
if not group:
|
||||||
return
|
return
|
||||||
|
|
||||||
group = group[0].id()
|
group = group[0].id()
|
||||||
|
|
||||||
pset = ifcopenshell.util.element.get_pset(element, self.pset_name)
|
pset = ifcopenshell.util.element.get_pset(element, self.pset_name)
|
||||||
index = pset['Index']
|
index = pset["Index"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj.name = original_names[group][index]
|
obj.name = original_names[group][index]
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_element_assembly(element):
|
def get_element_assembly(element):
|
||||||
if element.is_a("IfcElementAssembly"):
|
if element.is_a("IfcElementAssembly"):
|
||||||
@@ -1263,9 +1257,9 @@ class RefreshLinkedAggregate(bpy.types.Operator):
|
|||||||
selected_matrix = selected_obj.matrix_world
|
selected_matrix = selected_obj.matrix_world
|
||||||
object_duplicate = tool.Ifc.get_object(element)
|
object_duplicate = tool.Ifc.get_object(element)
|
||||||
duplicate_matrix = object_duplicate.matrix_world.decompose()
|
duplicate_matrix = object_duplicate.matrix_world.decompose()
|
||||||
|
|
||||||
original_names = get_original_names(element)
|
original_names = get_original_names(element)
|
||||||
|
|
||||||
delete_objects(element)
|
delete_objects(element)
|
||||||
|
|
||||||
for obj in context.selected_objects:
|
for obj in context.selected_objects:
|
||||||
@@ -1280,24 +1274,24 @@ class RefreshLinkedAggregate(bpy.types.Operator):
|
|||||||
matrix_diff = Matrix.inverted(selected_matrix) @ new_obj.matrix_world
|
matrix_diff = Matrix.inverted(selected_matrix) @ new_obj.matrix_world
|
||||||
new_obj_matrix = new_base_matrix @ matrix_diff
|
new_obj_matrix = new_base_matrix @ matrix_diff
|
||||||
new_obj.matrix_world = new_obj_matrix
|
new_obj.matrix_world = new_obj_matrix
|
||||||
|
|
||||||
for old, new in old_to_new.items():
|
for old, new in old_to_new.items():
|
||||||
if element_aggregate and new[0].is_a("IfcElementAssembly"):
|
if element_aggregate and new[0].is_a("IfcElementAssembly"):
|
||||||
new_aggregate = ifcopenshell.util.element.get_aggregate(new[0])
|
new_aggregate = ifcopenshell.util.element.get_aggregate(new[0])
|
||||||
|
|
||||||
if not new_aggregate:
|
if not new_aggregate:
|
||||||
blenderbim.core.aggregate.assign_object(
|
blenderbim.core.aggregate.assign_object(
|
||||||
tool.Ifc,
|
tool.Ifc,
|
||||||
tool.Aggregate,
|
tool.Aggregate,
|
||||||
tool.Collector,
|
tool.Collector,
|
||||||
relating_obj=tool.Ifc.get_object(element_aggregate),
|
relating_obj=tool.Ifc.get_object(element_aggregate),
|
||||||
related_obj=tool.Ifc.get_object(new[0]),
|
related_obj=tool.Ifc.get_object(new[0]),
|
||||||
)
|
)
|
||||||
|
|
||||||
for old, new in old_to_new.items():
|
for old, new in old_to_new.items():
|
||||||
new_obj = tool.Ifc.get_object(new[0])
|
new_obj = tool.Ifc.get_object(new[0])
|
||||||
set_original_name(new_obj, original_names)
|
set_original_name(new_obj, original_names)
|
||||||
|
|
||||||
blenderbim.bim.handler.refresh_ui_data()
|
blenderbim.bim.handler.refresh_ui_data()
|
||||||
|
|
||||||
operator_time = time() - refresh_start_time
|
operator_time = time() - refresh_start_time
|
||||||
|
|||||||
@@ -438,7 +438,7 @@ Scenario: Override duplicate move - copying an aggregate
|
|||||||
And the object "IfcElementAssembly/Assembly.001" exists
|
And the object "IfcElementAssembly/Assembly.001" exists
|
||||||
And the object "IfcElementAssembly/Assembly.001" is in the collection "IfcElementAssembly/Assembly.001"
|
And the object "IfcElementAssembly/Assembly.001" is in the collection "IfcElementAssembly/Assembly.001"
|
||||||
And the collection "IfcElementAssembly/Assembly.001" is in the collection "IfcBuildingStorey/My Storey"
|
And the collection "IfcElementAssembly/Assembly.001" is in the collection "IfcBuildingStorey/My Storey"
|
||||||
|
|
||||||
Scenario: Override duplicate move - copying objects with connection
|
Scenario: Override duplicate move - copying objects with connection
|
||||||
Given an empty IFC project
|
Given an empty IFC project
|
||||||
And I load the demo construction library
|
And I load the demo construction library
|
||||||
@@ -467,7 +467,7 @@ Scenario: Override duplicate move - copying objects with connection
|
|||||||
Then the object "IfcSlab/Slab.001" exists
|
Then the object "IfcSlab/Slab.001" exists
|
||||||
And the variable "slab_name" is "[o.name for o in bpy.context.selected_objects if o.name == 'IfcSlab/Slab.001'][0]"
|
And the variable "slab_name" is "[o.name for o in bpy.context.selected_objects if o.name == 'IfcSlab/Slab.001'][0]"
|
||||||
Then the object "{wall_name}" has a connection with "{slab_name}"
|
Then the object "{wall_name}" has a connection with "{slab_name}"
|
||||||
|
|
||||||
Scenario: Override duplicate move - copying walls with mitre joint
|
Scenario: Override duplicate move - copying walls with mitre joint
|
||||||
Given an empty IFC project
|
Given an empty IFC project
|
||||||
And I load the demo construction library
|
And I load the demo construction library
|
||||||
@@ -494,7 +494,7 @@ Scenario: Override duplicate move - copying walls with mitre joint
|
|||||||
Then the object "IfcWall/Wall.003" exists
|
Then the object "IfcWall/Wall.003" exists
|
||||||
And the variable "wall_name2" is "[o.name for o in bpy.context.selected_objects if o.name == 'IfcWall/Wall.003'][0]"
|
And the variable "wall_name2" is "[o.name for o in bpy.context.selected_objects if o.name == 'IfcWall/Wall.003'][0]"
|
||||||
Then the object "{wall_name1}" has a connection with "{wall_name2}"
|
Then the object "{wall_name1}" has a connection with "{wall_name2}"
|
||||||
|
|
||||||
Scenario: Override duplicate move linked - without active IFC data
|
Scenario: Override duplicate move linked - without active IFC data
|
||||||
Given an empty Blender session
|
Given an empty Blender session
|
||||||
And I add a cube
|
And I add a cube
|
||||||
@@ -588,7 +588,7 @@ Scenario: Refresh linked aggregate - after deleting an object
|
|||||||
When I refresh linked aggregate the selected object
|
When I refresh linked aggregate the selected object
|
||||||
Then the object "IfcWall/Wall_01" does not exist
|
Then the object "IfcWall/Wall_01" does not exist
|
||||||
And the object "IfcWall/Wall_02" exists
|
And the object "IfcWall/Wall_02" exists
|
||||||
|
|
||||||
Scenario: Refresh linked aggregate - after duplicating an object
|
Scenario: Refresh linked aggregate - after duplicating an object
|
||||||
Given I load the IFC test file "/test/files/linked-aggregates.ifc"
|
Given I load the IFC test file "/test/files/linked-aggregates.ifc"
|
||||||
And the object "IfcWall/Wall_01" is selected
|
And the object "IfcWall/Wall_01" is selected
|
||||||
@@ -606,4 +606,4 @@ Scenario: Refresh linked aggregate - after duplicating an object
|
|||||||
Then the object "IfcWall/Wall_01.001" exists
|
Then the object "IfcWall/Wall_01.001" exists
|
||||||
And the object "IfcWall/Wall_02.001" exists
|
And the object "IfcWall/Wall_02.001" exists
|
||||||
And the object "IfcWall/Wall_03.001" exists
|
And the object "IfcWall/Wall_03.001" exists
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user