Skip to content

Commit ac315e8

Browse files
committed
ifcfm cobie 2.4 - color code excel tabs
example - https://i.imgur.com/tSeqyjj.png
1 parent b7c1822 commit ac315e8

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/ifcfm/ifcfm/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,23 @@ def write_ods(self, output: str) -> None:
271271
def write_xlsx(self, output: str) -> None:
272272
workbook = Workbook()
273273

274-
cell_formats = {}
274+
cell_formats: dict[str, PatternFill] = {}
275275
for key, value in self.config.get("colours", {}).items():
276276
fill = PatternFill(start_color=value, end_color=value, fill_type="solid")
277277
cell_formats[key] = fill
278278

279279
for category, data in self.categories.items():
280-
colours = self.config.get("categories", {}).get(category, {}).get("colours", [])
280+
category_data = self.config.get("categories", {}).get(category, {})
281+
colours = category_data.get("colours", ())
281282

282283
if category in workbook.sheetnames:
283284
worksheet = workbook[category]
284285
else:
285286
worksheet = workbook.create_sheet(category)
286287

288+
if category_colour := category_data.get("colour", None):
289+
worksheet.sheet_properties.tabColor = cell_formats[category_colour].start_color.rgb
290+
287291
r = 1 # Openpyxl uses 1-based indexing
288292
c = 1
289293
for header in data["headers"]:

src/ifcfm/ifcfm/cobie24.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,7 @@ def get_sheet_name(element: ifcopenshell.entity_instance) -> Union[str, None]:
11411141
"bool_false": "No",
11421142
"categories": {
11431143
"Contact": {
1144+
"colour": "r",
11441145
"keys": ["Email"],
11451146
"headers": [
11461147
"Email",
@@ -1169,6 +1170,7 @@ def get_sheet_name(element: ifcopenshell.entity_instance) -> Union[str, None]:
11691170
"get_element_data": get_contact_data,
11701171
},
11711172
"Facility": {
1173+
"colour": "r",
11721174
"keys": ["Name"],
11731175
"headers": [
11741176
"Name",
@@ -1200,6 +1202,7 @@ def get_sheet_name(element: ifcopenshell.entity_instance) -> Union[str, None]:
12001202
"get_element_data": get_facility_data,
12011203
},
12021204
"Floor": {
1205+
"colour": "r",
12031206
"keys": ["Name"],
12041207
"headers": [
12051208
"Name",
@@ -1219,6 +1222,7 @@ def get_sheet_name(element: ifcopenshell.entity_instance) -> Union[str, None]:
12191222
"get_element_data": get_floor_data,
12201223
},
12211224
"Space": {
1225+
"colour": "r",
12221226
"keys": ["Name"],
12231227
"headers": [
12241228
"Name",
@@ -1241,6 +1245,7 @@ def get_sheet_name(element: ifcopenshell.entity_instance) -> Union[str, None]:
12411245
"get_element_data": get_space_data,
12421246
},
12431247
"Zone": {
1248+
"colour": "o",
12441249
"keys": ["Name", "Category", "SpaceNames"],
12451250
"headers": [
12461251
"Name",
@@ -1259,6 +1264,7 @@ def get_sheet_name(element: ifcopenshell.entity_instance) -> Union[str, None]:
12591264
"get_element_data": get_zone_data,
12601265
},
12611266
"Type": {
1267+
"colour": "r",
12621268
"keys": ["Name"],
12631269
"headers": [
12641270
"Name",
@@ -1303,6 +1309,7 @@ def get_sheet_name(element: ifcopenshell.entity_instance) -> Union[str, None]:
13031309
"get_element_data": get_type_data,
13041310
},
13051311
"Component": {
1312+
"colour": "r",
13061313
"keys": ["Name"],
13071314
"headers": [
13081315
"Name",
@@ -1331,6 +1338,7 @@ def get_sheet_name(element: ifcopenshell.entity_instance) -> Union[str, None]:
13311338
"get_element_data": get_component_data,
13321339
},
13331340
"System": {
1341+
"colour": "o",
13341342
"keys": ["Name", "Category", "ComponentNames"],
13351343
"headers": [
13361344
"Name",
@@ -1349,6 +1357,7 @@ def get_sheet_name(element: ifcopenshell.entity_instance) -> Union[str, None]:
13491357
"get_element_data": get_system_data,
13501358
},
13511359
"Assembly": { # Note that this is technically "not required"
1360+
"colour": "o",
13521361
"keys": ["Name", "SheetName", "ParentName"],
13531362
"headers": [
13541363
"Name",
@@ -1369,6 +1378,7 @@ def get_sheet_name(element: ifcopenshell.entity_instance) -> Union[str, None]:
13691378
"get_element_data": get_assembly_data,
13701379
},
13711380
"Connection": { # Note that this is technically "not required"
1381+
"colour": "o",
13721382
"keys": ["Name", "ConnectionType", "RowName1", "RowName2"],
13731383
"headers": [
13741384
"Name",
@@ -1392,6 +1402,7 @@ def get_sheet_name(element: ifcopenshell.entity_instance) -> Union[str, None]:
13921402
"get_element_data": get_connection_data,
13931403
},
13941404
"Spare": {
1405+
"colour": "r",
13951406
"keys": ["Name"],
13961407
"headers": [
13971408
"Name",
@@ -1413,6 +1424,7 @@ def get_sheet_name(element: ifcopenshell.entity_instance) -> Union[str, None]:
14131424
"get_element_data": get_spare_data,
14141425
},
14151426
"Resource": {
1427+
"colour": "r",
14161428
"keys": ["Name"],
14171429
"headers": [
14181430
"Name",
@@ -1430,6 +1442,7 @@ def get_sheet_name(element: ifcopenshell.entity_instance) -> Union[str, None]:
14301442
"get_element_data": get_resource_data,
14311443
},
14321444
"Job": {
1445+
"colour": "r",
14331446
"keys": ["Name", "TypeName", "TaskNumber"],
14341447
"headers": [
14351448
"Name",
@@ -1458,6 +1471,7 @@ def get_sheet_name(element: ifcopenshell.entity_instance) -> Union[str, None]:
14581471
"get_element_data": get_job_data,
14591472
},
14601473
"Document": {
1474+
"colour": "r",
14611475
"keys": ["Name", "Stage", "SheetName", "RowName"],
14621476
"headers": [
14631477
"Name",
@@ -1482,6 +1496,7 @@ def get_sheet_name(element: ifcopenshell.entity_instance) -> Union[str, None]:
14821496
"get_element_data": get_document_data,
14831497
},
14841498
"Attribute": {
1499+
"colour": "o",
14851500
"keys": ["Name", "SheetName", "RowName"],
14861501
"headers": [
14871502
"Name",
@@ -1504,6 +1519,7 @@ def get_sheet_name(element: ifcopenshell.entity_instance) -> Union[str, None]:
15041519
"get_element_data": pass_category_elements_as_data,
15051520
},
15061521
"Coordinate": {
1522+
"colour": "o",
15071523
"keys": ["Name", "SheetName", "RowName"],
15081524
"headers": (
15091525
"Name",

0 commit comments

Comments
 (0)