From 22edbddd84c43b70bd63f9c54fdbcb319a1932e1 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 27 Sep 2023 14:17:46 +1000 Subject: [PATCH] You can now interact with IfcFM via CLI --- .../blenderbim/bim/module/fm/prop.py | 2 +- src/ifcfm/ifcfm/__main__.py | 37 +++++++++++++++++++ src/ifcfm/ifcfm/{cobie.py => cobie24.py} | 0 .../ifcopenshell/util/fm.py | 1 + 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/ifcfm/ifcfm/__main__.py rename src/ifcfm/ifcfm/{cobie.py => cobie24.py} (100%) diff --git a/src/blenderbim/blenderbim/bim/module/fm/prop.py b/src/blenderbim/blenderbim/bim/module/fm/prop.py index 120de1a747..e05312038c 100644 --- a/src/blenderbim/blenderbim/bim/module/fm/prop.py +++ b/src/blenderbim/blenderbim/bim/module/fm/prop.py @@ -37,7 +37,7 @@ class BIMFMProperties(PropertyGroup): items=[ ("aohbsem", "AOH-BSEM", ""), ("basic", "Basic", ""), - ("cobie", "COBie 2.4", ""), + ("cobie24", "COBie 2.4", ""), ("cobie3", "COBie 3", ""), ], name="Engine", diff --git a/src/ifcfm/ifcfm/__main__.py b/src/ifcfm/ifcfm/__main__.py new file mode 100644 index 0000000000..6b0fac9cb7 --- /dev/null +++ b/src/ifcfm/ifcfm/__main__.py @@ -0,0 +1,37 @@ +import ifcfm +import argparse +import ifcopenshell + +parser = argparse.ArgumentParser(description="Extracts FM data from IFC to spreadsheets") +parser.add_argument( + "-p", + "--preset", + type=str, + default="basic", + help="The FM standard to extract. Built-in preset standards include cobie24, cobie3, aohbsem, and basic.", +) +parser.add_argument("-i", "--ifc", type=str, required=True, help="The IFC file") +parser.add_argument("-s", "--spreadsheet", type=str, default="output.ods", help="The spreadsheet file, or directory if the format is csv. Defaults to output.ods") +parser.add_argument( + "-f", "--format", type=str, default="ods", help="The format, chosen from csv, ods, or xlsx. Defaults to ods." +) +parser.add_argument("-d", "--delimiter", type=str, default=",", help="The delimiter in CSV. Defaults to a comma.") +parser.add_argument("-n", "--null", type=str, default="N/A", help="How to represent null values. Defaults to N/A.") +parser.add_argument( + "-e", "--empty", type=str, default="-", help="How to represent empty strings. Defaults to a hyphen." +) +parser.add_argument("--bool_true", type=str, default="YES", help="How to represent true values. Defaults to YES.") +parser.add_argument("--bool_false", type=str, default="NO", help="How to represent false values. Defaults to NO.") +args = parser.parse_args() + +ifc_file = ifcopenshell.open(args.ifc) +parser = ifcfm.Parser(preset=args.preset) +parser.parse(ifc_file) +writer = ifcfm.Writer(parser) +writer.write(null=args.null, empty=args.empty, bool_true=args.bool_true, bool_false=args.bool_false) +if args.format == "csv": + writer.write_csv(args.spreadsheet, delimiter=args.delimiter) +elif args.format == "ods": + writer.write_ods(args.spreadsheet) +elif args.format == "xlsx": + writer.write_xlsx(args.spreadsheet) diff --git a/src/ifcfm/ifcfm/cobie.py b/src/ifcfm/ifcfm/cobie24.py similarity index 100% rename from src/ifcfm/ifcfm/cobie.py rename to src/ifcfm/ifcfm/cobie24.py diff --git a/src/ifcopenshell-python/ifcopenshell/util/fm.py b/src/ifcopenshell-python/ifcopenshell/util/fm.py index f1c41f65e9..b58d688c99 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/fm.py +++ b/src/ifcopenshell-python/ifcopenshell/util/fm.py @@ -19,6 +19,7 @@ import ifcopenshell import ifcopenshell.util.attribute +# COBie actually uses an exclusion list, but this inclusion list is equivalent. cobie_type_classes = [ "IfcDoorStyle", "IfcBuildingElementProxyType",