Revise COBie 2.4 contact table mapping in collaboration with Emma Hooper

This commit is contained in:
Dion Moult
2023-09-29 12:56:53 +10:00
parent 89d3ee995d
commit 34b0970c6b
2 changed files with 1562 additions and 52 deletions
+53 -52
View File
@@ -35,7 +35,7 @@ import ifcopenshell.util.classification
def get_contacts(ifc_file): def get_contacts(ifc_file):
return ifc_file.by_type("IfcPersonAndOrganization") return ifc_file.by_type("IfcActor")
def get_facilities(ifc_file): def get_facilities(ifc_file):
@@ -265,51 +265,55 @@ def get_attributes(ifc_file):
def get_contact_data(ifc_file, element): def get_contact_data(ifc_file, element):
email = get_email_from_pao(element) the_actor = element.Theactor
history = get_history(ifc_file) if the_actor.is_a("IfcPerson"):
pao = None
person = the_actor
organization = None
elif the_actor.is_a("IfcOrganization"):
pao = None
person = None
organization = the_actor
elif the_actor.is_a("IfcPersonAndOrganization"):
pao = the_actor
person = the_actor.ThePerson
organization = the_actor.TheOrganization
roles = [] email = get_email_from_pao(person, organization)
for actor in [element, element.ThePerson, element.TheOrganization]:
roles = set()
for actor in [pao, person, organization]:
if not actor:
continue
for role in actor.Roles or []: for role in actor.Roles or []:
if role.Role == "USERDEFINED": if role.Role == "USERDEFINED":
if role.UserDefinedRole: if role.UserDefinedRole:
roles.append(role.UserDefinedRole) roles.add(role.UserDefinedRole)
else: else:
roles.append(role.Role) roles.add(role.Role)
organization = element.TheOrganization
person = element.ThePerson
department = get_pao_address(element, "InternalLocation")
if not department:
for rel in organization.Relates:
for org in rel.RelatedOrganizations:
if val(org.Name):
department = org.Name
return { return {
"key": email, "key": email,
"Email": email, "Email": email,
"CreatedBy": get_email_from_history(history) if history else None, "CreatedBy": get_created_by(element),
"CreatedOn": ifcopenshell.util.date.ifc2datetime(history.CreationDate).isoformat() if history else None, "CreatedOn": get_created_on(element),
"Category": ",".join(roles), "Category": ",".join(roles),
"Company": getattr(organization, "Name", None), "Company": getattr(organization, "Name", None),
"Phone": get_pao_address(element, "TelephoneNumbers"), "Phone": get_pao_address(person, organisation, "TelephoneNumbers"),
"ExternalSystem": history.OwningApplication.ApplicationFullName if history else None, "ExternalSystem": get_external_system(element),
"ExternalObject": element.is_a(), "ExternalObject": element.is_a(),
"ExternalIdentifier": email, "ExternalIdentifier": element.GlobalId,
"Department": department, "Department": get_pao_address(person, organisation, "InternalLocation"),
"OrganizationCode": getattr(organization, "Id", getattr(organization, "Identification", None)) "OrganizationCode": getattr(organization, "Id", getattr(organization, "Identification", None)),
or organization.Name,
"GivenName": getattr(person, "GivenName", None), "GivenName": getattr(person, "GivenName", None),
"FamilyName": getattr(person, "FamilyName", None), "FamilyName": getattr(person, "FamilyName", None),
"Street": get_pao_address(element, "AddressLines"), "Street": get_pao_address(person, organisation, "AddressLines"),
"PostalBox": get_pao_address(element, "PostalBox"), "PostalBox": get_pao_address(person, organisation, "PostalBox"),
"Town": get_pao_address(element, "Town"), "Town": get_pao_address(person, organisation, "Town"),
"StateRegion": get_pao_address(element, "Region"), "StateRegion": get_pao_address(person, organisation, "Region"),
"PostalCode": get_pao_address(element, "PostalCode"), "PostalCode": get_pao_address(person, organisation, "PostalCode"),
"Country": get_pao_address(element, "Country"), "Country": get_pao_address(person, organisation, "Country"),
} }
@@ -961,28 +965,23 @@ def get_created_by(element):
def get_email_from_history(element): def get_email_from_history(element):
pao = element.OwningUser pao = element.OwningUser
if pao.is_a("IfcPersonAndOrganization"): if pao.is_a("IfcPersonAndOrganization"):
return get_email_from_pao(pao) return get_email_from_pao(pao.ThePerson, pao.TheOrganization)
elif pao.is_a("IfcPerson"):
return get_email_from_pao(pao, None)
elif pao.is_a("IfcOrganization"):
return get_email_from_pao(None, pao)
def get_email_from_pao(pao): def get_email_from_pao(person, organization):
for address in pao.ThePerson.Addresses or []: if organization:
if address.is_a("IfcTelecomAddress") and address.ElectronicMailAddresses: for address in organization.Addresses or []:
return address.ElectronicMailAddresses[0] if address.is_a("IfcTelecomAddress") and address.ElectronicMailAddresses:
return address.ElectronicMailAddresses[0]
for address in pao.TheOrganization.Addresses or []: if person:
if address.is_a("IfcTelecomAddress") and address.ElectronicMailAddresses: for address in person.Addresses or []:
return address.ElectronicMailAddresses[0] if address.is_a("IfcTelecomAddress") and address.ElectronicMailAddresses:
return address.ElectronicMailAddresses[0]
person_id = getattr(pao.ThePerson, "Identification", getattr(pao.ThePerson, "Id", None))
if person_id:
return person_id
organization_id = getattr(pao.TheOrganization, "Identification", getattr(pao.TheOrganization, "Id", None))
if organization_id:
return organization_id
if pao.ThePerson.GivenName and pao.ThePerson.FamilyName and pao.TheOrganization.Name:
return pao.ThePerson.GivenName + pao.ThePerson.FamilyName + "@" + pao.TheOrganization.Name + ".com"
def get_owner_name(element): def get_owner_name(element):
@@ -1076,8 +1075,10 @@ def get_category(element):
return val(getattr(element, "ObjectType", None)) return val(getattr(element, "ObjectType", None))
def get_pao_address(element, name): def get_pao_address(person, organization, name):
for actor in [element.ThePerson, element.TheOrganization]: for actor in [organization, person]:
if not actor:
continue
for address in actor.Addresses or []: for address in actor.Addresses or []:
if hasattr(address, name) and getattr(address, name, None): if hasattr(address, name) and getattr(address, name, None):
result = getattr(address, name) result = getattr(address, name)
File diff suppressed because it is too large Load Diff