mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
typing
This commit is contained in:
@@ -46,29 +46,25 @@ def assign_group(
|
||||
ifcopenshell.api.group.assign_group(model,
|
||||
products=model.by_type("IfcFurniture"), group=group)
|
||||
"""
|
||||
settings = {
|
||||
"products": products,
|
||||
"group": group,
|
||||
}
|
||||
|
||||
if not settings["products"]:
|
||||
if not products:
|
||||
return
|
||||
|
||||
if not settings["group"].IsGroupedBy:
|
||||
is_grouped_by: tuple[ifcopenshell.entity_instance, ...]
|
||||
if not (is_grouped_by := group.IsGroupedBy):
|
||||
return file.create_entity(
|
||||
"IfcRelAssignsToGroup",
|
||||
**{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(file),
|
||||
"RelatedObjects": settings["products"],
|
||||
"RelatingGroup": settings["group"],
|
||||
}
|
||||
"RelatedObjects": products,
|
||||
"RelatingGroup": group,
|
||||
},
|
||||
)
|
||||
rel = settings["group"].IsGroupedBy[0]
|
||||
rel = is_grouped_by[0]
|
||||
related_objects = set(rel.RelatedObjects) or set()
|
||||
products = set(settings["products"])
|
||||
if products.issubset(related_objects):
|
||||
products_set = set(products)
|
||||
if products_set.issubset(related_objects):
|
||||
return rel
|
||||
rel.RelatedObjects = list(related_objects | products)
|
||||
rel.RelatedObjects = list(related_objects | products_set)
|
||||
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
|
||||
return rel
|
||||
|
||||
@@ -26,11 +26,8 @@ def edit_group(file: ifcopenshell.file, group: ifcopenshell.entity_instance, att
|
||||
IfcGroup, consult the IFC documentation.
|
||||
|
||||
:param group: The IfcGroup entity you want to edit
|
||||
:type group: ifcopenshell.entity_instance
|
||||
:param attributes: a dictionary of attribute names and values.
|
||||
:type attributes: dict
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
|
||||
@@ -40,7 +37,5 @@ def edit_group(file: ifcopenshell.file, group: ifcopenshell.entity_instance, att
|
||||
ifcopenshell.api.group.edit_group(model,
|
||||
group=group, attributes={"Description": "All furniture and joinery included in the unit"})
|
||||
"""
|
||||
settings = {"group": group, "attributes": attributes}
|
||||
|
||||
for name, value in settings["attributes"].items():
|
||||
setattr(settings["group"], name, value)
|
||||
for name, value in attributes.items():
|
||||
setattr(group, name, value)
|
||||
|
||||
@@ -46,17 +46,12 @@ def unassign_group(
|
||||
bad_furniture = furniture[0]
|
||||
ifcopenshell.api.group.unassign_group(model, products=[bad_furniture], group=group)
|
||||
"""
|
||||
settings = {
|
||||
"products": products,
|
||||
"group": group,
|
||||
}
|
||||
|
||||
if not settings["group"].IsGroupedBy:
|
||||
if not group.IsGroupedBy:
|
||||
return
|
||||
rel = settings["group"].IsGroupedBy[0]
|
||||
rel = group.IsGroupedBy[0]
|
||||
related_objects = set(rel.RelatedObjects) or set()
|
||||
products = set(settings["products"])
|
||||
related_objects -= products
|
||||
products_set = set(products)
|
||||
related_objects -= products_set
|
||||
if related_objects:
|
||||
rel.RelatedObjects = list(related_objects)
|
||||
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
|
||||
|
||||
@@ -45,24 +45,19 @@ def update_group_products(
|
||||
ifcopenshell.api.group.update_group_products(model,
|
||||
products=model.by_type("IfcFurniture"), group=group)
|
||||
"""
|
||||
settings = {
|
||||
"group": group,
|
||||
"products": products,
|
||||
}
|
||||
|
||||
if not settings["group"].IsGroupedBy:
|
||||
if not group.IsGroupedBy:
|
||||
return file.create_entity(
|
||||
"IfcRelAssignsToGroup",
|
||||
**{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(file),
|
||||
"RelatedObjects": settings["products"],
|
||||
"RelatingGroup": settings["group"],
|
||||
"RelatedObjects": products,
|
||||
"RelatingGroup": group,
|
||||
}
|
||||
)
|
||||
else:
|
||||
rels = settings["group"].IsGroupedBy
|
||||
objects = set(settings["products"])
|
||||
rels = group.IsGroupedBy
|
||||
objects = set(products)
|
||||
for rel in rels:
|
||||
objects.update([g for g in rel.RelatedObjects if g.is_a("IfcGroup")])
|
||||
to_purge = rels[1:]
|
||||
|
||||
Reference in New Issue
Block a user