forked from Moult/IfcClassification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vbis.py
55 lines (52 loc) · 1.89 KB
/
vbis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import csv
import os
import json
#import pystache
import subprocess
import ifcopenshell
from pathlib import Path
class Generator():
def __init__(self):
self.file = ifcopenshell.file(schema='IFC4')
self.out_dir = './'
def generate(self):
classification = self.file.create_entity('IfcClassification', **{
'Source': 'VBIS',
'Edition': 'May-20',
'EditionDate': '2020-05-01',
'Name': 'VBIS',
'Description': '',
'Location': 'https://vbis.com.au/',
'ReferenceTokens': ['-']
})
# We assume all the Excel spreadsheets are re-exported in CSV format
for filename in Path('./').glob('*.csv'):
with open(filename, newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
name = None
levels = [None, None, None, None]
ref = classification
for i, row in enumerate(reader):
if i <= 4:
continue
if row[0]:
name = row[0]
elif row[1]:
name = row[1]
elif row[2]:
name = row[2]
elif row[3]:
name = row[3]
ref = self.file.create_entity('IfcClassificationReference', **{
'Identification': row[4],
'Name': name
})
cur_level = len(row[4].split('-')) - 1
levels[cur_level] = ref
if cur_level == 0:
ref.ReferencedSource = classification
else:
ref.ReferencedSource = levels[cur_level-1]
self.file.write('VBIS.ifc')
generator = Generator()
generator.generate()