-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallplan_ifc.py
41 lines (40 loc) · 1.74 KB
/
allplan_ifc.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
import os
script_path = os.path.abspath(os.path.dirname(__file__))
work_path = os.path.abspath(os.getcwd())
ifc_file = []
for file in os.listdir(work_path):
if file.endswith('.ifc') and not file.endswith('_clean.ifc'):
ifc_file.append(os.path.join(work_path, file))
assert len(ifc_file) > 0
for ifc_loc in ifc_file:
new_filename = ifc_loc.replace(".ifc", '_clean.ifc')
with open(ifc_loc, 'r') as f1, open(new_filename, 'w') as f2:
content = f1.read()
# remove end line characters
content = content.replace("\n", "")
lines = content.split(");")
for line in lines:
if "IFCQUANTITYLENGTH" in line:
line = line.replace("IFCQUANTITYLENGTH", "IFCPROPERTYSINGLEVALUE")
txt = line.split(",")
txt[3] = "IFCINTEGER(" + txt[3].split(".")[0]+ ")"
txt.pop(1)
line = ",".join(txt)
if "IFCQUANTITYWEIGHT" in line:
line = line.replace("IFCQUANTITYWEIGHT", "IFCPROPERTYSINGLEVALUE")
txt = line.split(",")
txt[3] = "IFCREAL(" + txt[3]+ ")"
txt.pop(1)
line = ",".join(txt)
if "IFCQUANTITYCOUNT" in line:
line = line.replace("IFCQUANTITYCOUNT", "IFCPROPERTYSINGLEVALUE")
txt = line.split(",")
txt[3] = "IFCINTEGER(" + txt[3].split(".")[0]+ ")"
txt.pop(1)
line = ",".join(txt)
if "IFCELEMENTQUANTITY" in line and 'AllplanQuantities' in line:
line = line.replace("IFCELEMENTQUANTITY", "IFCPROPERTYSET")
txt = line.split(",")
txt.pop(3)
line = ",".join(txt)
f2.write(line+");\n")