mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-16 10:34:31 +00:00
32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
class Patcher:
|
|
def __init__(self, src, file, logger, args=None):
|
|
self.src = src
|
|
self.file = file
|
|
self.logger = logger
|
|
self.args = args
|
|
|
|
def patch(self):
|
|
project = self.file.by_type('IfcProject')[0]
|
|
spatial_elements = self.find_decomposed_ifc_class(project, self.args[0])
|
|
for spatial_element in spatial_elements:
|
|
self.patch_placement_to_origin(spatial_element)
|
|
|
|
def find_decomposed_ifc_class(self, element, ifc_class):
|
|
results = []
|
|
rel_aggregates = element.IsDecomposedBy
|
|
if not rel_aggregates:
|
|
return results
|
|
for rel_aggregate in rel_aggregates:
|
|
for part in rel_aggregate.RelatedObjects:
|
|
if part.is_a(ifc_class):
|
|
results.append(part)
|
|
results.extend(self.find_decomposed_ifc_class(part, ifc_class))
|
|
return results
|
|
|
|
def patch_placement_to_origin(self, element):
|
|
element.ObjectPlacement.RelativePlacement.Location.Coordinates = (0., 0., 0.)
|
|
if element.ObjectPlacement.RelativePlacement.Axis:
|
|
element.ObjectPlacement.RelativePlacement.Axis.DirectionRatios = (0., 0., 1.)
|
|
if element.ObjectPlacement.RelativePlacement.RefDirection:
|
|
element.ObjectPlacement.RelativePlacement.RefDirection.DirectionRatios = (1., 0., 0.)
|