From a00449e34bf5e5daf183fae47c6fc03370b4daf1 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sun, 1 Dec 2019 22:17:23 +1100 Subject: [PATCH] Export clash results to JSON with metadata --- src/ifcblenderexport/ifcclash/clash.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/ifcblenderexport/ifcclash/clash.py b/src/ifcblenderexport/ifcclash/clash.py index 4448f3de80..5ac1f2ceb4 100644 --- a/src/ifcblenderexport/ifcclash/clash.py +++ b/src/ifcblenderexport/ifcclash/clash.py @@ -2,6 +2,7 @@ import ifcopenshell import ifcopenshell.geom import numpy as np import fcl +import json class IfcClasher: def __init__(self): @@ -34,11 +35,19 @@ class IfcClasher: for contact in rdata.result.contacts: if contact.penetration_depth < self.tolerance: continue + a_global_id = self.a_geom_to_global_id[id(contact.o1)] + b_global_id = self.b_geom_to_global_id[id(contact.o2)] + a = self.a.by_guid(a_global_id) + b = self.b.by_guid(b_global_id) self.clashes.append({ - 'a': self.a_geom_to_global_id[id(contact.o1)], - 'b': self.b_geom_to_global_id[id(contact.o2)], - 'normal': contact.normal, - 'position': contact.pos, + 'a_global_id': a_global_id, + 'b_global_id': b_global_id, + 'a_ifc_class': a.is_a(), + 'b_ifc_class': b.is_a(), + 'a_name': a.Name, + 'b_name': b.Name, + 'normal': list(contact.normal), + 'position': list(contact.pos), 'penetration_depth': contact.penetration_depth }) @@ -121,5 +130,6 @@ class IfcClasher: ifc_clasher = IfcClasher() ifc_clasher.clash() -import pprint -pprint.pprint(ifc_clasher.clashes) + +with open('clashes.json', 'w', encoding='utf-8') as clashes_file: + json.dump(ifc_clasher.clashes, clashes_file, indent=4)