-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSV_Reader.py
More file actions
176 lines (156 loc) · 5.93 KB
/
Copy pathCSV_Reader.py
File metadata and controls
176 lines (156 loc) · 5.93 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
# -*- coding: utf-8 -*-
"""CSV Reader
Contains Functions:
---ReadCSV(configLoc,myPart,myFixt,config)
--- Returns the provided config dictionary instance, filled with the parsed CSV data
"""
import gom
import DictBuilder
from collections import defaultdict
import csv
def ReadCSV(configLoc,myPart,myFixt,config):
"""Read CSV
Keyword arguments:
configLoc -- File location of the Config .CSV
myPart -- string: 4 Digit Part #
myFixt -- string: 3 Character Fixture ID
config -- Object: instance of the config dictionary class
Returns the provided config dictionary instance, filled with the parsed CSV data
"""
found = False
with open(configLoc,'r') as csvfile:
reader = csv.reader(csvfile,delimiter=',')
for row in reader:
if myPart in row[1] and myFixt in row[0]:
found = True
_fixturePoints = row[13].split(',')
fixturePoints = []
for f in _fixturePoints:
fixturePoints.append(int(f))
_numParts = row[3].split(',')
numParts = []
for np in _numParts:
numParts.append(np)
_iTemplate = row[7].split(',')
inspectionTemplate = []
for it in _iTemplate:
inspectionTemplate.append(row[6]+it)
_xOffset = row[14].split(',')
xOffset = []
for x in _xOffset:
xOffset.append(int(x))
_yOffset = row[15].split(',')
yOffset = []
for y in _yOffset:
yOffset.append(int(y))
_zOffset = row[16].split(',')
zOffset = []
for z in _zOffset:
zOffset.append(int(z))
_zRotArray = row[17].split(',')
zRotArray = []
for zr in _zRotArray:
zRotArray.append(int(zr))
lComp = int(row[18])
wComp = int(row[19])
hComp = int(row[20])
directory = row[2]
meshArea = int(row[21])
_winSPCname = row[8].split(',')
winSPCname = []
partNR = []
for name in _winSPCname:
winSPCname.append(name)
partNR.append(name[0:13])
key_Location = row[5]
_key_Material = row[9].split(',')
key_Material = []
for km in _key_Material:
key_Material.append(km)
_key_Print = row[10].split(',')
key_Print = []
for kp in _key_Print:
key_Print.append(kp)
_key_PartName = row[11].split(',')
key_PartName = []
for kpn in _key_PartName:
key_PartName.append(kpn)
key_System = str(row[12])
_nestID = row[4].split(',')
nestID = []
for n in _nestID:
splitter = n.split(';')
nestID.append(splitter)
nestID = [list(map(int, x)) for x in nestID]
_manualDialogTitleArray = row[22].split(',')
manualDialogTitleArray = []
for title in _manualDialogTitleArray:
manualDialogTitleArray.append(title)
_manualDialogTextArray = row[23].split(',')
manualDialogTextArray = []
for text in _manualDialogTextArray:
manualDialogTextArray.append(text)
_manualDialogTypeArray = row[24].split(',')
manualDialogTypeArray = []
for type in _manualDialogTypeArray:
manualDialogTypeArray.append(type)
if found == False:
print('$$$ DEBUG : CANNOT LOCATE TEMPLATE FOR VMR: '+myPart+myFixt)
NOTMP=gom.script.sys.execute_user_defined_dialog (content='<dialog>' \
' <title>Message</title>' \
' <style></style>' \
' <control id="OkCancel"/>' \
' <position>automatic</position>' \
' <embedding>always_toplevel</embedding>' \
' <sizemode>automatic</sizemode>' \
' <size height="184" width="322"/>' \
' <content rows="2" columns="2">' \
' <widget row="0" column="0" columnspan="2" type="display::text" rowspan="1">' \
' <name>text</name>' \
' <tooltip></tooltip>' \
' <text><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">' \
'<html><head><meta name="qrichtext" content="1" /><style type="text/css">' \
'p, li { white-space: pre-wrap; }' \
'</style></head><body style=" ">' \
'<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">ERROR: NO CONFIGURATION TEMPLATE FOUND</span></p></body></html></text>' \
' <wordwrap>false</wordwrap>' \
' </widget>' \
' <widget row="1" column="0" columnspan="1" type="label" rowspan="1">' \
' <name>label</name>' \
' <tooltip></tooltip>' \
' <text>'+myPart+'</text>' \
' <word_wrap>false</word_wrap>' \
' </widget>' \
' <widget row="1" column="1" columnspan="1" type="label" rowspan="1">' \
' <name>label_1</name>' \
' <tooltip></tooltip>' \
' <text>'+myFixt+'</text>' \
' <word_wrap>false</word_wrap>' \
' </widget>' \
' </content>' \
'</dialog>')
globalArrayLists = [fixturePoints, numParts, inspectionTemplate, xOffset, yOffset, zOffset, zRotArray, winSPCname, key_Material, key_Print, key_PartName, nestID, partNR, manualDialogTitleArray, manualDialogTextArray, manualDialogTypeArray]
globalArrayKeys = ['fixturePoints', 'numParts', 'inspectionTemplate', 'xOffset', 'yOffset', 'zOffset', 'zRotArray', 'winSPCname', 'key_Material', 'key_Print', 'key_PartName', 'nestID', 'partNR', 'manualDialogTitleArray', 'manualDialogTextArray', 'manualDialogTypeArray']
arrayPosition = 0
if len(globalArrayKeys) == len(globalArrayLists):
for array in globalArrayLists:
#print('Array Start: ',array)
for item in array:
#print('Subitem: ',item)
#print('Array: ',array)
config.add([(globalArrayKeys[arrayPosition],item)])
#print (arrayPosition)
arrayPosition+=1
else:
print('ERROR: Mismatch in Keys & Lists')
globalVariableList = [lComp, wComp, hComp, directory, meshArea,key_Location, key_System]
globalVariableKeys = ['lComp', 'wComp', 'hComp', 'directory', 'meshArea', 'key_Location', 'key_System']
arrayPosition = 0
if len(globalVariableKeys) == len(globalVariableList):
for var in globalVariableList:
#print('Var Start: ',var)
config.add([(globalVariableKeys[arrayPosition],var)])
arrayPosition+=1
else:
print('ERROR: Mismatch in Keys & Lists')
return config