-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathcreate_property_dump.py
94 lines (69 loc) · 3.22 KB
/
create_property_dump.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import glob
import operator
import xml_dict
from xmi_document import xmi_document
NS_QTO = "http://www.buildingsmart-tech.org/xml/qto/QTO_IFC4.xsd"
def format_TypePropertySingleValue(prop):
try:
return prop.children[0].attributes["type"]
except KeyError as e:
return ""
def format_TypePropertyEnumeratedValue(prop):
return " ".join(map(operator.attrgetter("text"), prop.children[0].children))
def format_TypePropertyTableValue(prop):
return "/".join((
prop.child_with_tag("DefinedValue").children[0].attributes["type"],
prop.child_with_tag("DefiningValue").children[0].attributes["type"]
))
def format_TypePropertyReferenceValue(prop):
return prop.attributes["reftype"]
def format_TypePropertyListValue(prop):
return prop.children[0].children[0].attributes["type"]
def format_TypeComplexProperty(prop):
return " ".join(map(lambda n: n.child_with_tag("Name").text, prop.children))
format_TypePropertyBoundedValue = format_TypePropertySingleValue
def get_property_definitions():
for fn in glob.glob("../reference_schemas/psd/Pset_*.xml"):
xd = xml_dict.read(fn)
pset = xd.child_with_tag("Name").text
for prop in xd.child_with_tag("PropertyDefs").children:
pname = prop.child_with_tag("Name").text
try:
pdef = prop.child_with_tag("Definition").text
except:
pdef = "-"
proptypenode = prop.child_with_tag('PropertyType').children[0]
proptype = proptypenode.tag
proptypeargs = globals()[f"format_{proptype}"](proptypenode)
proptypeifc = f"Ifc{proptype[4:]}"
yield pname, pset, proptypeifc, proptypeargs, pdef
for fn in glob.glob("../reference_schemas/psd/Qto_*.xml"):
xd = xml_dict.read(fn)
qset = xd.child_with_tag(f'{{{NS_QTO}}}Name').text
for prop in xd.child_with_tag(f'{{{NS_QTO}}}QtoDefs').children:
qname = prop.child_with_tag(f'{{{NS_QTO}}}Name').text
qtype = prop.child_with_tag(f'{{{NS_QTO}}}QtoType').text
try:
qdef = prop.child_with_tag(f'{{{NS_QTO}}}Definition').text
except:
qdef = "-"
yield qname, qset, "Quantity", qtype, qdef
xmi_doc = xmi_document("../schemas/IFC.xml")
for item in xmi_doc:
if item.type == "ENTITY":
for nm, df in item.definition.attributes:
yield nm, item.name, 'ATTRIBUTE', df, ''
if __name__ == "__main__":
import xlsxwriter
workbook = xlsxwriter.Workbook("properties_by_name.xlsx")
header_format = workbook.add_format({'bg_color': 'black', 'font_color': 'white'})
worksheet = workbook.add_worksheet("Properties")
worksheet.write(0, 0, "name", header_format)
worksheet.write(0, 1, "pset name / entity", header_format)
worksheet.write(0, 2, "type", header_format)
worksheet.write(0, 3, "type arguments", header_format)
worksheet.write(0, 4, "definition", header_format)
for i, row in enumerate(sorted(get_property_definitions())):
for j, cell in enumerate(row):
worksheet.write(i+1, j, cell)
workbook.close()