mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 13:48:03 +00:00
Fix #839. Add upstream support for IFCJSON, including compact, v4, and v5a
This commit is contained in:
@@ -267,6 +267,13 @@ endif
|
|||||||
# Provides IFCCSV functionality
|
# Provides IFCCSV functionality
|
||||||
cd dist/blenderbim/libs/site/packages/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifccsv/ifccsv.py
|
cd dist/blenderbim/libs/site/packages/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifccsv/ifccsv.py
|
||||||
|
|
||||||
|
# Provides IFCJSON functionality
|
||||||
|
mkdir dist/working
|
||||||
|
cd dist/working && wget https://github.com/IFCJSON-Team/IFC2JSON_python/archive/master.zip
|
||||||
|
cd dist/working && unzip master.zip
|
||||||
|
cp -r dist/working/IFC2JSON_python-master/ifcjson dist/blenderbim/libs/site/packages/
|
||||||
|
rm -rf dist/working
|
||||||
|
|
||||||
# Provides IFCPatch functionality
|
# Provides IFCPatch functionality
|
||||||
cd dist/blenderbim/libs/site/packages/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcpatch/ifcpatch.py
|
cd dist/blenderbim/libs/site/packages/ && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcpatch/ifcpatch.py
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ from .helper import SIUnitHelper
|
|||||||
from . import schema
|
from . import schema
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import addon_utils
|
import addon_utils
|
||||||
from .ifc2json import IFC2JSON
|
|
||||||
|
|
||||||
class ArrayModifier:
|
class ArrayModifier:
|
||||||
count: int
|
count: int
|
||||||
@@ -2868,9 +2867,17 @@ class IfcExporter():
|
|||||||
elif extension == 'ifc':
|
elif extension == 'ifc':
|
||||||
self.file.write(self.ifc_export_settings.output_file)
|
self.file.write(self.ifc_export_settings.output_file)
|
||||||
elif extension == 'ifcjson':
|
elif extension == 'ifcjson':
|
||||||
ifc2json = IFC2JSON(self.file).convert()
|
import ifcjson
|
||||||
with open(self.ifc_export_settings.output_file, 'w') as f:
|
if self.ifc_export_settings.json_version == '4':
|
||||||
f.write(json.dumps(ifc2json, indent = 4))
|
jsonData = ifcjson.IFC2JSON4(self.file, self.ifc_export_settings.json_compact).spf2Json()
|
||||||
|
with open(self.ifc_export_settings.output_file, 'w') as outfile:
|
||||||
|
json.dump(jsonData, outfile,
|
||||||
|
indent=None if self.ifc_export_settings.json_compact else 4)
|
||||||
|
elif self.ifc_export_settings.json_version == '5a':
|
||||||
|
jsonData = ifcjson.IFC2JSON5a(self.file, self.ifc_export_settings.json_compact).spf2Json()
|
||||||
|
with open(self.ifc_export_settings.output_file, 'w') as outfile:
|
||||||
|
json.dump(jsonData, outfile,
|
||||||
|
indent=None if self.ifc_export_settings.json_compact else 4)
|
||||||
|
|
||||||
|
|
||||||
class IfcExportSettings:
|
class IfcExportSettings:
|
||||||
@@ -2900,6 +2907,8 @@ class IfcExportSettings:
|
|||||||
settings.data_dir = scene_bim.data_dir
|
settings.data_dir = scene_bim.data_dir
|
||||||
settings.schema_dir = scene_bim.schema_dir
|
settings.schema_dir = scene_bim.schema_dir
|
||||||
settings.has_representations = scene_bim.export_has_representations
|
settings.has_representations = scene_bim.export_has_representations
|
||||||
|
settings.json_version = scene_bim.export_json_version
|
||||||
|
settings.json_compact = scene_bim.export_json_compact
|
||||||
settings.schema = scene_bim.export_schema
|
settings.schema = scene_bim.export_schema
|
||||||
settings.should_use_presentation_style_assignment = scene_bim.export_should_use_presentation_style_assignment
|
settings.should_use_presentation_style_assignment = scene_bim.export_should_use_presentation_style_assignment
|
||||||
settings.should_guess_quantities = scene_bim.export_should_guess_quantities
|
settings.should_guess_quantities = scene_bim.export_should_guess_quantities
|
||||||
|
|||||||
@@ -1,106 +0,0 @@
|
|||||||
import ifcopenshell
|
|
||||||
|
|
||||||
class IFC2JSON:
|
|
||||||
def __init__(self, file):
|
|
||||||
self.file = file
|
|
||||||
self.id_objects = {}
|
|
||||||
self.jsonObjects = []
|
|
||||||
|
|
||||||
def convert(self):
|
|
||||||
# schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(self.file.schema)
|
|
||||||
entityIter = iter(self.file)
|
|
||||||
for entity in entityIter:
|
|
||||||
self.entityToDict(entity)
|
|
||||||
for key in self.id_objects:
|
|
||||||
self.jsonObjects.append(self.id_objects[key])
|
|
||||||
|
|
||||||
return {
|
|
||||||
'data': self.jsonObjects
|
|
||||||
}
|
|
||||||
|
|
||||||
def entityToDict(self, entity):
|
|
||||||
ref = {
|
|
||||||
'Type': entity.is_a()
|
|
||||||
}
|
|
||||||
attr_dict = entity.__dict__
|
|
||||||
|
|
||||||
# check for globalid
|
|
||||||
if 'GlobalId' in attr_dict:
|
|
||||||
ref['ref'] = attr_dict['GlobalId']
|
|
||||||
if not attr_dict['GlobalId'] in self.id_objects:
|
|
||||||
d = {
|
|
||||||
'Type': entity.is_a()
|
|
||||||
}
|
|
||||||
|
|
||||||
for i in range(0,len(entity)):
|
|
||||||
attr = entity.attribute_name(i)
|
|
||||||
if attr in attr_dict:
|
|
||||||
if not attr == 'OwnerHistory':
|
|
||||||
jsonValue = self.getEntityValue(attr_dict[attr])
|
|
||||||
if jsonValue:
|
|
||||||
d[attr] = jsonValue
|
|
||||||
if attr_dict[attr] == None:
|
|
||||||
continue
|
|
||||||
elif isinstance(attr_dict[attr], ifcopenshell.entity_instance):
|
|
||||||
d[attr] = self.entityToDict(attr_dict[attr])
|
|
||||||
elif isinstance(attr_dict[attr], tuple):
|
|
||||||
subEnts = []
|
|
||||||
for subEntity in attr_dict[attr]:
|
|
||||||
if isinstance(subEntity, ifcopenshell.entity_instance):
|
|
||||||
subEntJson = self.entityToDict(subEntity)
|
|
||||||
if subEntJson:
|
|
||||||
subEnts.append(subEntJson)
|
|
||||||
else:
|
|
||||||
subEnts.append(subEntity)
|
|
||||||
if len(subEnts) > 0:
|
|
||||||
d[attr] = subEnts
|
|
||||||
else:
|
|
||||||
d[attr] = attr_dict[attr]
|
|
||||||
self.id_objects[attr_dict['GlobalId']] = d
|
|
||||||
return ref
|
|
||||||
else:
|
|
||||||
d = {
|
|
||||||
'Type': entity.is_a()
|
|
||||||
}
|
|
||||||
|
|
||||||
for i in range(0,len(entity)):
|
|
||||||
attr = entity.attribute_name(i)
|
|
||||||
if attr in attr_dict:
|
|
||||||
if not attr == 'OwnerHistory':
|
|
||||||
jsonValue = self.getEntityValue(attr_dict[attr])
|
|
||||||
if jsonValue:
|
|
||||||
d[attr] = jsonValue
|
|
||||||
if attr_dict[attr] == None:
|
|
||||||
continue
|
|
||||||
elif isinstance(attr_dict[attr], ifcopenshell.entity_instance):
|
|
||||||
d[attr] = self.entityToDict(attr_dict[attr])
|
|
||||||
elif isinstance(attr_dict[attr], tuple):
|
|
||||||
subEnts = []
|
|
||||||
for subEntity in attr_dict[attr]:
|
|
||||||
if isinstance(subEntity, ifcopenshell.entity_instance):
|
|
||||||
# subEnts.append(None)
|
|
||||||
subEntJson = self.entityToDict(subEntity)
|
|
||||||
if subEntJson:
|
|
||||||
subEnts.append(subEntJson)
|
|
||||||
else:
|
|
||||||
subEnts.append(subEntity)
|
|
||||||
if len(subEnts) > 0:
|
|
||||||
d[attr] = subEnts
|
|
||||||
else:
|
|
||||||
d[attr] = attr_dict[attr]
|
|
||||||
return d
|
|
||||||
|
|
||||||
def getEntityValue(self, value):
|
|
||||||
if value == None:
|
|
||||||
jsonValue = None
|
|
||||||
elif isinstance(value, ifcopenshell.entity_instance):
|
|
||||||
jsonValue = self.entityToDict(value)
|
|
||||||
elif isinstance(value, tuple):
|
|
||||||
jsonValue = None
|
|
||||||
subEnts = []
|
|
||||||
for subEntity in value:
|
|
||||||
subEnts.append(self.getEntityValue(subEntity))
|
|
||||||
jsonValue = subEnts
|
|
||||||
else:
|
|
||||||
jsonValue = value
|
|
||||||
return jsonValue
|
|
||||||
@@ -1003,6 +1003,8 @@ class BIMProperties(PropertyGroup):
|
|||||||
name="Predefined Type", default=None)
|
name="Predefined Type", default=None)
|
||||||
ifc_userdefined_type: StringProperty(name="Userdefined Type")
|
ifc_userdefined_type: StringProperty(name="Userdefined Type")
|
||||||
export_schema: EnumProperty(items=[('IFC4', 'IFC4', ''), ('IFC2X3', 'IFC2X3', '')], name='IFC Schema')
|
export_schema: EnumProperty(items=[('IFC4', 'IFC4', ''), ('IFC2X3', 'IFC2X3', '')], name='IFC Schema')
|
||||||
|
export_json_version: EnumProperty(items=[('4', '4', ''), ('5a', '5a', '')], name='IFC JSON Version')
|
||||||
|
export_json_compact: BoolProperty(name="Export Compact IFCJSON", default=False)
|
||||||
export_has_representations: BoolProperty(name="Export Representations", default=True)
|
export_has_representations: BoolProperty(name="Export Representations", default=True)
|
||||||
export_should_guess_quantities: BoolProperty(name="Export with Guessed Quantities", default=False)
|
export_should_guess_quantities: BoolProperty(name="Export with Guessed Quantities", default=False)
|
||||||
export_should_use_presentation_style_assignment: BoolProperty(name="Export with Presentation Style Assignment", default=False)
|
export_should_use_presentation_style_assignment: BoolProperty(name="Export with Presentation Style Assignment", default=False)
|
||||||
|
|||||||
@@ -1558,6 +1558,8 @@ class BIM_PT_mvd(Panel):
|
|||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(bim_properties, 'export_schema')
|
row.prop(bim_properties, 'export_schema')
|
||||||
|
row = layout.row()
|
||||||
|
row.prop(bim_properties, 'export_json_version')
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(bim_properties, 'ifc_import_filter')
|
row.prop(bim_properties, 'ifc_import_filter')
|
||||||
@@ -1589,6 +1591,8 @@ class BIM_PT_mvd(Panel):
|
|||||||
row.prop(bim_properties, 'import_should_use_cpu_multiprocessing')
|
row.prop(bim_properties, 'import_should_use_cpu_multiprocessing')
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(bim_properties, 'import_should_import_with_profiling')
|
row.prop(bim_properties, 'import_should_import_with_profiling')
|
||||||
|
row = layout.row()
|
||||||
|
row.prop(bim_properties, 'export_json_compact')
|
||||||
|
|
||||||
layout.label(text='Simplifications:')
|
layout.label(text='Simplifications:')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user