-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbclconvertapp.py
More file actions
193 lines (173 loc) · 6.16 KB
/
bclconvertapp.py
File metadata and controls
193 lines (173 loc) · 6.16 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import Tkinter, tkMessageBox, sys, re, StringIO
from Tkinter import *
from tkFileDialog import askopenfilename
from tkFileDialog import asksaveasfilename
# run this on user click
def onClick():
try:
f = open(userDialog())
o = open(userSave(), 'w')
out = StringIO.StringIO()
out.write(trnMat(f, o))
out.write(trnAir(f, o))
out.write(trnCon(f, o))
print >>o, out.getvalue()
f.close()
o.close()
tkMessageBox.showinfo("Done!", "Conversion Complete")
except (RuntimeError, TypeError, NameError):
print "Unexpected error:", sys.exc_info()[0]
raise
# Provide user with dialog box to select the IDF file to process
def userDialog():
filename = askopenfilename(
filetypes=[('IDF Files','*.idf'), ('All Files','*')],
initialdir=['C:\\'],
title='Select IDF File to Process ...')
if filename == "":
tkMessageBox.showinfo('Info', 'User Cancelled')
else:
return filename
# Provide user with dialog box to select folder where processed
# files should be placed
def userSave():
savename = asksaveasfilename(
filetypes=[('INP Files','*.inp'), ('All Files','*')],
initialdir = ['C:\\'],
title='Save Output INP As ...',
initialfile='*.inp',
)
if savename == "":
tkMessageBox.showinfo("Info", "User Cancelled")
else:
return savename
# Translate all Construction definitions
def trnCon(f, o):
output = StringIO.StringIO()
line = f.readline()
x = []
while line:
str1 = 'Construction,'
str2 = ';'
str3 = ','
str4 = 'CostSource:'
if re.search(str4, line):
break
elif re.search(str1, line):
line = f.readline()
cName = line.split(str3)[0].strip()
cLayers = cName + ' Layers'
line = f.readline()
while (not re.search(str2, line)):
x.append(line.split(str3)[0].strip())
line = f.readline()
x.append(line.split(str2)[0].strip())
output.write('"' + cLayers + '" = LAYERS\n')
output.write('\tMATERIAL\t\t= ( ')
cnt = len(x)
for item in x:
if (cnt > 1):
output.write('"' + item + '", \n\t\t')
else:
output.write('"' + item + '" ')
cnt = cnt - 1
del x[:]
output.write(')\n')
output.write('\t..\n\n')
output.write('"' + cName + '"' + ' = CONSTRUCTION\n')
output.write('\tTYPE\t\t= LAYERS\n')
output.write('\tLAYERS\t\t= "' + cLayers + '"\n')
output.write('\t..\n\n')
else:
line = f.readline()
f.seek(0)
return output.getvalue()
# Translate all Material definitions
def trnMat(f, o):
output = StringIO.StringIO()
line = f.readline()
x = []
while line:
str1 = "Material,"
str2 = ";"
str3 = ","
if re.search(str1, line):
line = f.readline()
mName = line.split(str3)[0].strip()
line = f.readline()
mRuff = line.split(str3)[0].strip()
line = f.readline()
mThck = line.split(str3)[0].strip()
mThck = float(mThck) * 3.280840
line = f.readline()
mCond = line.split(str3)[0].strip()
mCond = float(mCond) * 0.577789
line = f.readline()
mDens = line.split(str3)[0].strip()
mDens = float(mDens) * 0.062428
line = f.readline()
if not re.search(str2, line):
mSphe = line.split(str3)[0].strip()
mSphe = float(mSphe) * 0.000239
line = f.readline()
mAbsT = line.split(str3)[0].strip()
line = f.readline()
mAbsS = line.split(str3)[0].strip()
line = f.readline()
mAbsV = line.split(str2)[0].strip()
else:
mSphe = line.split(str2)[0].strip()
mSphe = float(mSphe) * 0.000239
output.write('"' + mName + '" = MATERIAL\n')
output.write('\tTYPE\t\t\t= PROPERTIES\n')
output.write('\tTHICKNESS\t\t= ' + str(mThck) + '\n')
output.write('\tCONDUCTIVITY\t= ' + str(mCond) + '\n')
output.write('\tDENSITY\t\t\t= ' + str(mDens) + '\n')
output.write('\tSPECIFIC-HEAT\t= ' + str(mSphe) + '\n')
output.write('\t..\n\n')
else:
line = f.readline()
f.seek(0)
return output.getvalue()
# Translate all AirGap definitions
def trnAir(f, o):
output = StringIO.StringIO()
line = f.readline()
x = []
while line:
str1 = "Material:AirGap,"
str2 = ";"
str3 = ","
if re.search(str1, line):
line = f.readline()
aName = line.split(str3)[0].strip()
line = f.readline()
aRes = line.split(str2)[0].strip()
aRes = float(aRes) * 5.674467
output.write('"' + aName + '" = MATERIAL\n')
output.write('\tTYPE\t\t\t= RESISTANCE\n')
output.write('\tRESISTANCE\t\t= ' + str(aRes) + '\n')
output.write('\t..\n\n')
else:
line = f.readline()
f.seek(0)
return output.getvalue()
# user dialog to begin the conversion process
tk = Tk()
tk.title('IDF to INP Converter for NREL BCL')
Label(text='This application will take an EnergyPlus IDF contruction object '\
'downloaded from the NREL Building Component Library (http://bcl.nrel.gov) '\
'and convert it to a DOE2 INP format for use with eQUEST.\n\n'\
'Instructions:\n'\
'1. Select IDF file Downloaded from BCL.\n'\
'2. Select name and location to save new INP file.\n'\
'3. Done!',
font=("Calibri", 10),
justify=LEFT,
wraplength=400,
padx=10,
pady=10
).pack(pady=15)
Button(text='EXIT', font=("Calibri", 10), pady=10, padx=25, command=quit).pack(side=BOTTOM)
Button(text='CLICK to RUN Converter', font=("Calibri", 10), pady=10, command=onClick).pack(side=BOTTOM)
tk.mainloop()