コード例 #1
0
ファイル: export_ifc.py プロジェクト: Krande/IfcOpenShell
    def export(self):
        self.file = IfcStore.get_file()
        self.set_header()
        IfcStore.update_cache()
        if bpy.context.scene.BIMProjectProperties.is_authoring:
            self.sync_deletions()
            self.sync_all_objects()
            self.sync_edited_objects()
        extension = self.ifc_export_settings.output_file.split(".")[-1]
        if extension == "ifczip":
            with tempfile.TemporaryDirectory() as unzipped_path:
                filename, ext = os.path.splitext(os.path.basename(self.ifc_export_settings.output_file))
                tmp_filename = f"{filename}.ifc"
                tmp_file = os.path.join(unzipped_path, tmp_filename)
                self.file.write(tmp_file)
                with zipfile.ZipFile(
                    self.ifc_export_settings.output_file, mode="w", compression=zipfile.ZIP_DEFLATED, compresslevel=9
                ) as zf:
                    zf.write(tmp_file, arcname=tmp_filename)
        elif extension == "ifc":
            self.file.write(self.ifc_export_settings.output_file)
        elif extension == "ifcjson":
            import ifcjson

            if self.ifc_export_settings.json_version == "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)
コード例 #2
0
def generate_json(ifcFilePath, jsonFilePath):
    COMPACT = False
    INCLUDE_INVERSE = False
    EMPTY_PROPERTIES = False
    NO_OWNERHISTORY = True
    GEOMETRY = True
    jsonData = ifcjson.IFC2JSON4(ifcFilePath, COMPACT, INCLUDE_INVERSE,
                                 EMPTY_PROPERTIES, NO_OWNERHISTORY,
                                 GEOMETRY).spf2Json()
    with open(jsonFilePath, 'w') as outfile:
        json.dump(jsonData, outfile, indent=True)
    return jsonData


# generate_json("model.ifc", "output.json")
コード例 #3
0
            GEOMETRY = "tessellate"
        else:
            GEOMETRY = True
    else:
        GEOMETRY = True

    if os.path.isfile(ifcFilePath):
        if args.o:
            jsonFilePath = args.o
        else:
            jsonFilePath = os.path.splitext(ifcFilePath)[0] + '.json'
        if not args.v or args.v == "4":
            jsonData = ifcjson.IFC2JSON4(ifcFilePath,
                                         COMPACT,
                                         NO_INVERSE=args.no_inverse,
                                         EMPTY_PROPERTIES=args.empty_properties,
                                         NO_OWNERHISTORY=args.no_ownerhistory,
                                         GEOMETRY=GEOMETRY
                                         ).spf2Json()
            with open(jsonFilePath, 'w') as outfile:
                json.dump(jsonData, outfile, indent=indent)
        elif args.v == "5a":
            jsonData = ifcjson.IFC2JSON5a(ifcFilePath,
                                          COMPACT,
                                          EMPTY_PROPERTIES=args.empty_properties
                                          ).spf2Json()
            with open(jsonFilePath, 'w') as outfile:
                json.dump(jsonData, outfile, indent=indent)
        else:
            print('Version ' + args.v + ' is not supported')
    else:
コード例 #4
0
    if args.i:
        ifcFilePath = args.i
    else:
        ifcFilePath = './samples/7m900_tue_hello_wall_with_door.ifc'
    if args.compact:
        indent = None
        compact = True
    else:
        indent = 2
        compact = False

    if os.path.isfile(ifcFilePath):
        if args.o:
            jsonFilePath = args.o
        else:
            jsonFilePath = os.path.splitext(ifcFilePath)[0] + '.json'
        if not args.v or args.v == "4":
            jsonData = ifcjson.IFC2JSON4(ifcFilePath, compact).spf2Json()
            with open(jsonFilePath, 'w') as outfile:
                json.dump(jsonData, outfile, indent=indent)
        elif args.v == "5a":
            jsonData = ifcjson.IFC2JSON5a(ifcFilePath, compact).spf2Json()
            with open(jsonFilePath, 'w') as outfile:
                json.dump(jsonData, outfile, indent=indent)
        else:
            print('Version ' + args.v + ' is not supported')
    else:
        print(str(args.i) + ' is not a valid file')
t1_stop = perf_counter()
print("Conversion took ", t1_stop - t1_start, " seconds")
コード例 #5
0
import os
import ifcjson
import json
import ifcopenshell

# traverse root directory, and list directories as dirs and files as files
for root, dirs, files in os.walk("../Samples/"):
    path = root.split(os.sep)
    for file in files:
        inFilePath = os.path.join(root, file)
        filename, file_extension = os.path.splitext(inFilePath)
        if file_extension.lower() == '.ifc':

            # # First create normalized ifcopenshell ifc
            # model = ifcopenshell.open(inFilePath)
            # model.write(filename + '_ifcopenshell.ifc')

            jsonFilePath = filename + '.json'
            with open(jsonFilePath, 'w') as outfile:
                json.dump(ifcjson.IFC2JSON4(inFilePath).spf2Json(), outfile, indent=2)
            # with open(filename + '_python_5a.json', 'w') as outfile:
            #     json.dump(ifcjson.IFC2JSON5a(inFilePath).spf2Json(), outfile, indent=2)

            # Convert back to SPF
            ifc_json = ifcjson.JSON2IFC(jsonFilePath)
            ifc_model = ifc_json.ifcModel()
            ifc_model.write(filename + '_roundtrip.ifc')