mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-10 06:00:51 +00:00
ifccsv - support importing enum values #4608
This commit is contained in:
+15
-9
@@ -405,6 +405,7 @@ class IfcCsv:
|
||||
empty: str = "",
|
||||
bool_true: str = "YES",
|
||||
bool_false: str = "NO",
|
||||
concat: str = ", ",
|
||||
) -> None:
|
||||
"""
|
||||
Args:
|
||||
@@ -413,11 +414,11 @@ class IfcCsv:
|
||||
ext: FILE_FORMAT = table.split(".")[-1].lower()
|
||||
|
||||
if ext == "csv":
|
||||
self.import_csv(ifc_file, table, attributes, delimiter, null, empty, bool_true, bool_false)
|
||||
self.import_csv(ifc_file, table, attributes, delimiter, null, empty, bool_true, bool_false, concat)
|
||||
elif ext == "ods":
|
||||
self.import_ods(ifc_file, table, attributes, null, empty, bool_true, bool_false)
|
||||
self.import_ods(ifc_file, table, attributes, null, empty, bool_true, bool_false, concat)
|
||||
elif ext == "xlsx":
|
||||
self.import_xlsx(ifc_file, table, attributes, null, empty, bool_true, bool_false)
|
||||
self.import_xlsx(ifc_file, table, attributes, null, empty, bool_true, bool_false, concat)
|
||||
|
||||
def import_csv(
|
||||
self,
|
||||
@@ -429,6 +430,7 @@ class IfcCsv:
|
||||
empty: str = "",
|
||||
bool_true: str = "YES",
|
||||
bool_false: str = "NO",
|
||||
concat: str = ", ",
|
||||
) -> None:
|
||||
with open(table, newline="", encoding="utf-8") as f:
|
||||
reader = csv.reader(f, delimiter=delimiter)
|
||||
@@ -441,17 +443,19 @@ class IfcCsv:
|
||||
elif len(attributes) == len(headers) - 1:
|
||||
attributes.insert(0, "") # The GlobalId column
|
||||
continue
|
||||
self.process_row(ifc_file, row, headers, attributes, null, empty, bool_true, bool_false)
|
||||
self.process_row(ifc_file, row, headers, attributes, null, empty, bool_true, bool_false, concat)
|
||||
|
||||
def import_xlsx(self, ifc_file, table, attributes, null, empty, bool_true, bool_false):
|
||||
def import_xlsx(self, ifc_file, table, attributes, null, empty, bool_true, bool_false, concat) -> None:
|
||||
df = pd.read_excel(table)
|
||||
self.import_pd(ifc_file, df, attributes, null, empty, bool_true, bool_false)
|
||||
|
||||
def import_ods(self, ifc_file, table, attributes, null, empty, bool_true, bool_false):
|
||||
def import_ods(self, ifc_file, table, attributes, null, empty, bool_true, bool_false, concat) -> None:
|
||||
df = pd.read_excel(table, engine="odf")
|
||||
self.import_pd(ifc_file, df, attributes, null, empty, bool_true, bool_false)
|
||||
|
||||
def import_pd(self, ifc_file, df, attributes=None, null="-", empty="", bool_true="YES", bool_false="NO"):
|
||||
def import_pd(
|
||||
self, ifc_file, df, attributes=None, null="-", empty="", bool_true="YES", bool_false="NO", concat=", "
|
||||
) -> None:
|
||||
headers = df.columns.tolist()
|
||||
|
||||
if not attributes:
|
||||
@@ -460,7 +464,7 @@ class IfcCsv:
|
||||
attributes.insert(0, "") # The GlobalId column
|
||||
|
||||
for _, row in df.iterrows():
|
||||
self.process_row(ifc_file, row.tolist(), headers, attributes, null, empty, bool_true, bool_false)
|
||||
self.process_row(ifc_file, row.tolist(), headers, attributes, null, empty, bool_true, bool_false, concat)
|
||||
|
||||
def process_row(
|
||||
self,
|
||||
@@ -472,6 +476,7 @@ class IfcCsv:
|
||||
empty: str,
|
||||
bool_true: str,
|
||||
bool_false: str,
|
||||
concat: str,
|
||||
) -> None:
|
||||
try:
|
||||
element = ifc_file.by_guid(row[0])
|
||||
@@ -490,7 +495,7 @@ class IfcCsv:
|
||||
elif value == bool_false:
|
||||
value = False
|
||||
key = attributes[i] or headers[i]
|
||||
ifcopenshell.util.selector.set_element_value(ifc_file, element, key, value)
|
||||
ifcopenshell.util.selector.set_element_value(ifc_file, element, key, value, concat=concat)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -552,5 +557,6 @@ if __name__ == "__main__":
|
||||
delimiter=args.delimiter,
|
||||
null=args.null,
|
||||
empty=args.empty,
|
||||
concat=args.concat,
|
||||
)
|
||||
ifc_file.write(args.ifc)
|
||||
|
||||
Reference in New Issue
Block a user