mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 09:32:37 +00:00
You can now filter elements in IfcClash with either inclusion or exclusion IFC selectors
This commit is contained in:
+62
-10
@@ -3,6 +3,7 @@
|
|||||||
import collision
|
import collision
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.geom
|
import ifcopenshell.geom
|
||||||
|
import ifcopenshell.util.selector
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import json
|
import json
|
||||||
@@ -36,9 +37,10 @@ class IfcClasher:
|
|||||||
data['ifc'] = ifcopenshell.open(data['file'])
|
data['ifc'] = ifcopenshell.open(data['file'])
|
||||||
self.patch_ifc(data['ifc'])
|
self.patch_ifc(data['ifc'])
|
||||||
self.settings.logger.info(f'Purging unnecessary elements {ab} ...')
|
self.settings.logger.info(f'Purging unnecessary elements {ab} ...')
|
||||||
self.purge_elements(data['ifc'])
|
self.purge_elements(data)
|
||||||
self.settings.logger.info(f'Creating collision data for {ab} ...')
|
self.settings.logger.info(f'Creating collision data for {ab} ...')
|
||||||
self.add_collision_objects(data, getattr(self, f'{ab}_cm'))
|
if len(data['ifc'].by_type('IfcElement')) > 0:
|
||||||
|
self.add_collision_objects(data, getattr(self, f'{ab}_cm'))
|
||||||
results = self.a_cm.in_collision_other(self.b_cm, return_data=True)
|
results = self.a_cm.in_collision_other(self.b_cm, return_data=True)
|
||||||
|
|
||||||
if not results[0]:
|
if not results[0]:
|
||||||
@@ -79,10 +81,23 @@ class IfcClasher:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def purge_elements(self, ifc_file):
|
def purge_elements(self, data):
|
||||||
# TODO: more filtering abilities
|
if not data['selector']:
|
||||||
for element in ifc_file.by_type('IfcSpace'):
|
for element in data['ifc'].by_type('IfcSpace'):
|
||||||
ifc_file.remove(element)
|
ifc_file.remove(element)
|
||||||
|
return
|
||||||
|
|
||||||
|
selector = ifcopenshell.util.selector.Selector()
|
||||||
|
elements = selector.parse(data['ifc'], data['selector'])
|
||||||
|
|
||||||
|
if data['mode'] == 'e':
|
||||||
|
for element in data['ifc'].by_type('IfcElement'):
|
||||||
|
if element in elements:
|
||||||
|
data['ifc'].remove(element)
|
||||||
|
elif data['mode'] == 'i':
|
||||||
|
for element in data['ifc'].by_type('IfcElement'):
|
||||||
|
if element not in elements:
|
||||||
|
data['ifc'].remove(element)
|
||||||
|
|
||||||
def add_collision_objects(self, data, cm):
|
def add_collision_objects(self, data, cm):
|
||||||
iterator = ifcopenshell.geom.iterator(self.geom_settings, data['ifc'], multiprocessing.cpu_count())
|
iterator = ifcopenshell.geom.iterator(self.geom_settings, data['ifc'], multiprocessing.cpu_count())
|
||||||
@@ -175,12 +190,36 @@ if __name__ == '__main__':
|
|||||||
'-a',
|
'-a',
|
||||||
type=str,
|
type=str,
|
||||||
nargs='+',
|
nargs='+',
|
||||||
help='The IFC file containing group A of objects to clash')
|
help='The IFC files containing group A of objects to clash')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-b',
|
'-b',
|
||||||
type=str,
|
type=str,
|
||||||
nargs='+',
|
nargs='+',
|
||||||
help='The IFC file containing group B of objects to clash')
|
help='The IFC files containing group B of objects to clash')
|
||||||
|
parser.add_argument(
|
||||||
|
'-as',
|
||||||
|
'--a-selector',
|
||||||
|
type=str,
|
||||||
|
nargs='+',
|
||||||
|
help='Selector queries for each IFC file in group A')
|
||||||
|
parser.add_argument(
|
||||||
|
'-bs',
|
||||||
|
'--b-selector',
|
||||||
|
type=str,
|
||||||
|
nargs='+',
|
||||||
|
help='Selector queries for each IFC file in group B')
|
||||||
|
parser.add_argument(
|
||||||
|
'-am',
|
||||||
|
'--a-mode',
|
||||||
|
type=str,
|
||||||
|
nargs='+',
|
||||||
|
help='Selection mode for each file in group A. "i" for include, and "e" for exclude')
|
||||||
|
parser.add_argument(
|
||||||
|
'-bm',
|
||||||
|
'--b-mode',
|
||||||
|
type=str,
|
||||||
|
nargs='+',
|
||||||
|
help='Selection mode for each file in group B. "i" for include, and "e" for exclude')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-t',
|
'-t',
|
||||||
'--tolerance',
|
'--tolerance',
|
||||||
@@ -203,8 +242,21 @@ if __name__ == '__main__':
|
|||||||
handler.setLevel(logging.DEBUG)
|
handler.setLevel(logging.DEBUG)
|
||||||
settings.logger.addHandler(handler)
|
settings.logger.addHandler(handler)
|
||||||
ifc_clasher = IfcClasher(settings)
|
ifc_clasher = IfcClasher(settings)
|
||||||
ifc_clasher.a.extend([{'file': a, 'meshes': {}} for a in args.a])
|
for ab in ['a', 'b']:
|
||||||
ifc_clasher.b.extend([{'file': b, 'meshes': {}} for b in args.b])
|
getattr(ifc_clasher, ab).extend([{
|
||||||
|
'file': a,
|
||||||
|
'meshes': {},
|
||||||
|
'selector': '',
|
||||||
|
'mode': ''
|
||||||
|
} for i, a in enumerate(getattr(args, ab))])
|
||||||
|
|
||||||
|
if getattr(args, f'{ab}_selector'):
|
||||||
|
for i, selector in enumerate(getattr(args, f'{ab}_selector')):
|
||||||
|
getattr(ifc_clasher, ab)[i]['selector'] = selector
|
||||||
|
|
||||||
|
if getattr(args, f'{ab}_mode'):
|
||||||
|
for i, mode in enumerate(getattr(args, f'{ab}_mode')):
|
||||||
|
getattr(ifc_clasher, ab)[i]['mode'] = mode
|
||||||
ifc_clasher.tolerance = args.tolerance
|
ifc_clasher.tolerance = args.tolerance
|
||||||
ifc_clasher.clash()
|
ifc_clasher.clash()
|
||||||
ifc_clasher.export()
|
ifc_clasher.export()
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ class IfcAttributeExtractor():
|
|||||||
return getattr(prop, prop.is_a()[len('IfcQuantity'):] + 'Value')
|
return getattr(prop, prop.is_a()[len('IfcQuantity'):] + 'Value')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_qto_property(qto, name, avlue):
|
def set_qto_property(qto, name, value):
|
||||||
for prop in qto.Quantities:
|
for prop in qto.Quantities:
|
||||||
if prop.Name != name:
|
if prop.Name != name:
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user