Add new import workaround for 12D files with absolute coordinates.

This commit is contained in:
Dion Moult
2020-01-24 10:19:44 +11:00
parent 98e082ccac
commit f501aaeb01
3 changed files with 50 additions and 18 deletions
+28 -5
View File
@@ -164,6 +164,8 @@ class IfcImporter():
self.ifc_import_settings.should_ignore_site_coordinates = True
if self.is_ifc_class_far_away('IfcBuilding'):
self.ifc_import_settings.should_ignore_building_coordinates = True
elif applications[0].ApplicationFullName == '12D Model':
self.ifc_import_settings.should_reset_absolute_coordinates = True
def is_ifc_class_far_away(self, ifc_class):
for site in self.file.by_type(ifc_class):
@@ -171,13 +173,15 @@ class IfcImporter():
or not site.ObjectPlacement.RelativePlacement \
or not site.ObjectPlacement.RelativePlacement.Location:
continue
coordinates = site.ObjectPlacement.RelativePlacement.Location.Coordinates
# Arbitrary threshold based on experience
if abs(coordinates[0]) > 1000000 \
or abs(coordinates[1]) > 1000000 \
or abs(coordinates[2]) > 1000000:
if self.is_point_far_away(site.ObjectPlacement.RelativePlacement.Location):
return True
def is_point_far_away(self, point):
# Arbitrary threshold based on experience
return abs(point.Coordinates[0]) > 1000000 \
or abs(point.Coordinates[1]) > 1000000 \
or abs(point.Coordinates[2]) > 1000000
def patch_ifc(self):
project = self.file.by_type('IfcProject')[0]
if self.ifc_import_settings.should_ignore_site_coordinates:
@@ -188,6 +192,24 @@ class IfcImporter():
buildings = self.find_decomposed_ifc_class(project, 'IfcBuilding')
for building in buildings:
self.patch_placement_to_origin(building)
if self.ifc_import_settings.should_reset_absolute_coordinates:
self.reset_absolute_coordinates()
def reset_absolute_coordinates(self):
# 12D can have some funky coordinates out of any sensible range. This
# method will not work all the time, but will catch most issues.
offset_point = None
for point in self.file.by_type('IfcCartesianPoint'):
if len(point.Coordinates) == 2 or not self.is_point_far_away(point):
continue
if not offset_point:
offset_point = (point.Coordinates[0], point.Coordinates[1], point.Coordinates[2])
self.ifc_import_settings.logger.info(f'Resetting absolute coordinates by {point}')
point.Coordinates = (
point.Coordinates[0] - offset_point[0],
point.Coordinates[1] - offset_point[1],
point.Coordinates[2] - offset_point[2]
)
def find_decomposed_ifc_class(self, element, ifc_class):
results = []
@@ -545,6 +567,7 @@ class IfcImportSettings:
self.should_auto_set_workarounds = True
self.should_ignore_site_coordinates = False
self.should_ignore_building_coordinates = False
self.should_reset_absolute_coordinates = False
self.should_import_curves = False
self.should_treat_styled_item_as_material = False
self.should_use_cpu_multiprocessing = False
+1
View File
@@ -331,6 +331,7 @@ class BIMProperties(PropertyGroup):
export_should_use_presentation_style_assignment: BoolProperty(name="Export with Presentation Style Assignment", default=False)
import_should_ignore_site_coordinates: BoolProperty(name="Import Ignoring Site Coordinates", default=False)
import_should_ignore_building_coordinates: BoolProperty(name="Import Ignoring Building Coordinates", default=False)
import_should_reset_absolute_coordinates: BoolProperty(name="Import Resetting Absolute Coordinates", default=False)
import_should_import_curves: BoolProperty(name="Import Curves", default=False)
import_should_auto_set_workarounds: BoolProperty(name="Automatically Set Vendor Workarounds", default=True)
import_should_treat_styled_item_as_material: BoolProperty(name="Import Treating Styled Item as Material", default=False)
+21 -13
View File
@@ -574,31 +574,39 @@ class BIM_PT_mvd(Panel):
scene = context.scene
bim_properties = scene.BIMProperties
layout.label(text="Custom MVD:")
layout.label(text='Custom MVD:')
row = layout.row()
row.prop(bim_properties, "export_has_representations")
row.prop(bim_properties, 'export_has_representations')
row = layout.row()
row.prop(bim_properties, "import_should_import_curves")
row.prop(bim_properties, 'import_should_import_curves')
layout.label(text="Experimental Modes:")
layout.label(text='Experimental Modes:')
row = layout.row()
row.prop(bim_properties, "import_should_use_legacy")
row.prop(bim_properties, 'import_should_use_legacy')
row = layout.row()
row.prop(bim_properties, "import_should_use_cpu_multiprocessing")
row.prop(bim_properties, 'import_should_use_cpu_multiprocessing')
layout.label(text="Revit Workarounds:")
layout.label(text='Vendor Workarounds:')
row = layout.row()
row.prop(bim_properties, "import_should_auto_set_workarounds")
row.prop(bim_properties, 'import_should_auto_set_workarounds')
layout.label(text='12D Workarounds:')
row = layout.row()
row.prop(bim_properties, "export_should_export_all_materials_as_styled_items")
row.prop(bim_properties, 'import_should_reset_absolute_coordinates')
layout.label(text='Revit Workarounds:')
row = layout.row()
row.prop(bim_properties, "export_should_use_presentation_style_assignment")
row.prop(bim_properties, 'export_should_export_all_materials_as_styled_items')
row = layout.row()
row.prop(bim_properties, "import_should_ignore_site_coordinates")
row.prop(bim_properties, 'export_should_use_presentation_style_assignment')
row = layout.row()
row.prop(bim_properties, "import_should_ignore_building_coordinates")
row.prop(bim_properties, 'import_should_ignore_site_coordinates')
row = layout.row()
row.prop(bim_properties, "import_should_treat_styled_item_as_material")
row.prop(bim_properties, 'import_should_ignore_building_coordinates')
row = layout.row()
row.prop(bim_properties, 'import_should_treat_styled_item_as_material')