-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_update.py
67 lines (61 loc) · 1.79 KB
/
test_update.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
56
57
58
59
60
61
62
63
64
65
66
67
"""
test_update.py
Test add a single Revit parameter.
- Given:
- a Revit native speckle object with
- 1 correct parameter and
- 1 missing parameter,
- a Revit to IFC mapping file
- Identify required changes based on IDS
"""
import re
import os
from pprint import pprint
SAMPLE_MAPPING = os.path.join(os.getcwd(), "examples", "RevitMapping.txt")
def parsePropertySet(string):
prop_arr = string.split("\t")
if(len(prop_arr) != 4):
return None
return prop_arr
def parseProperty(string):
prop_arr = string.split("\t")
return prop_arr
def parseRevitMapping(path):
"""
Parse mapping based on a Revit IFC mapping file
"""
text = ""
with open(path, "r") as f:
text = f.read()
pass
seq = re.compile('(^[^#].*)', re.MULTILINE)
prop_sets = {}
current_pset = ""
for match in seq.finditer(text):
invalid = True
text = match.groups()[0]
cleaned = text.replace("\n", "")
cleaned = cleaned.replace(" ", "")
cleaned = cleaned.split("#")[0]
propset_arr = None
if("PropertySet" in cleaned):
propset_arr = parsePropertySet(cleaned)
if propset_arr == None:
current_pset = ""
continue
current_pset = propset_arr[1]
prop_sets[current_pset] = {}
pass
if current_pset == "": continue
if(cleaned[0:1] == "\t"):
prop_arr = parseProperty(cleaned)
if prop_arr == None: continue
prop_sets[current_pset].update(
{"ifc": prop_arr[1], "other": prop_arr[3], "type": prop_arr[2]}
)
pass
return prop_sets
if __name__ == "__main__":
prop_sets = parseRevitMapping(SAMPLE_MAPPING)
pprint(prop_sets);
pass