Back to SDS/2 Parametric Scripts
## GetData.py version 1.00
## Copyright (c)
2007
## All rights
reserved.
## NOT FOR
########################################################################################
"""
Class definition -
Upon instantiation, the data file is read and a dictionary is created
containing connection data. User selects the LE and RE
connection from a dialog box menu
in the calling script.
"""
from param import
Warning
import os
class GetData(object):
def __init__(self,
fn):
#if os.path.isfile(fn):
try:
f = open(fn,
'r')
self.labels
= f.readline().split('\t')
dataList = []
for line
in f:
if not
line.startswith('#'):
dataList.append(line.strip().split('\t'))
f.close()
self.data
= dataList
self.dict
= {}
for item
in dataList:
self.dict[item[0]] =
item[1:]
except:
Warning("Data
file was not found or\n Data file was invalid or\nAn
error occured in '__init__'")
self.labels
= None
self.data
= None
self.dict
= None
def __iter__(self):
for item in self.data:
yield item
def __repr__(self):
return
'<data file list object, GetData class>'
###################################
def test_script():
from macrolib.PrintDict import formatDict
from macrolib.FileDefaults import job_Defaults_path
from param import ResponseNotOK,
Dialog, Warning
variable_listLE =
['vbSetbackL', 'vbLapL', 'plateThkL', 'plateLenL', 'plateHorDimL',\
'plateHeightL', 'plateVertDimL',
'bmGaL', 'clipSizeBmL',\
'bm1stDimL', 'bmRows_bmSpaL', 'colGaL', 'clipSizeColL',\
'col1stDimL', 'colRows_colSpaL', 'clipWeldSzL']
data_file_path = job_Defaults_path()
data_file =
"VB_Hovensa_Connections.txt"
while True:
b = GetData(os.path.join(data_file_path, data_file))
print formatDict("Instance attribute b.dict:",
b.dict)
connList
= []
for item in b:
connList.append(item[0])
## DIALOG
dlg1 = Dialog(
"Connection Information")
dlg1.menu("print_doc",
("Yes", "No"), "No", "Print parametric
script documentation only ")
dlg1.tabset_begin()
dlg1.tab("Connection
Selection")
dlg1.group_title("Left
End")
dlg1.menu('conn_markLE', connList, conn_markLE, "Select connection")
dlg1.group_title_end()
dlg1.group_title("Right
End")
dlg1.menu('conn_markRE', connList, conn_markRE, "Select connection")
dlg1.group_title_end()
try:
dd1 = dlg1.done()
except ResponseNotOK:
break
# Update the local namespace
for key, value
in dd1.items():
exec
"%s = %s" % (key, repr(value)) in None
if print_doc == "Yes":
print
__doc__
break
# Assign data values to variable names
from variable_listLE and variable_listRE
# Left end connection
for i in range(len(variable_listLE)):
try:
exec
"%s = float(%s)" % (variable_listLE[i], repr(b.dict[conn_markLE][i])) in None
except:
exec
"%s = %s" % (variable_listLE[i], repr(b.dict[conn_markLE][i])) in None
print
"%s = %s" % (variable_listLE[i], repr(eval(variable_listLE[i])))
bmRowsL,
bmSpaL = bmRows_bmSpaL.split('@')
colRowsL,
colSpaL = colRows_colSpaL.split('@')
bmRowsL,
colRowsL = map(int, [bmRowsL, colRowsL])
bmSpaL,
colSpaL = map(float, [bmSpaL,
colSpaL])
for var in ['bmRowsL', 'bmSpaL', 'colRowsL', 'colSpaL']:
print
"%s = %s" % (var, eval(var))
## End test_script()
if __name__ == '__main__':
try:
test_script()
finally:
del GetData
Tab-delimited
data file
#
Mark Brace Setback Brace Lap Plate Thk Plate Length Plate Hor Dim Plate Height Plate
Vert Dim
BR3 17.125 9.5 0.75 17 11.25 19.25 15.8125 4.25 L3x3x1/2 5 4@3 4.25 L3x3x1/2 5 4@3 0.25
BR4 15.75 9.5 0.75 16 10.5 20 16.5 4.125 L3x3x1/2 5 4@3 4.125 L3x3x1/2 5 4@3 0.25
BR5 20.375 9.5 0.75 18.125 13.4375 18.8125 14.3125 4.25 L3x3x1/2 5 4@3 4.25 L3x3x1/2 5.25 4@3 0.25
BR101 18.0 10.0 0.625 22.0 19.5 20.625 16.625 5.0 L4x3x3/8 4.5 5@3.5 5.25 L4x3x5/16 6.25 3@4 0.25
BR102 23.0 9.5 0.75 16.5 8.125 21.6875 16.5625 4.5 L3 1/2x3x1/2 4 4@3.25 5.5 L4x3x1/2 6 4@3.5 0.25