-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvalueExporter.cod
275 lines (242 loc) · 7.24 KB
/
valueExporter.cod
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
REM --------------------------------
REM #region Global Variables
REM --------------------------------
Dim constCR = ASCII(13)
Dim constLF = ASCII(10)
Dim constQT = ASCII(34)
Dim constTAB = ASCII(9)
Dim OptionList as Array()
Dim targetOption = ""
Dim targetNumber = 0
Dim root = MAPPATH_ITEMS + "AgileBIM"
Dim Skipped = ""
REQUIRES task
REM #endregion
REM --------------------------------
REM #region C# Excluded CID's
REM --------------------------------
REM BAD CID: 4522
REM This needs an offline map of various options, but none of them effect the dimensional layout.
REM BAD CID: 876 (Causing Fatal Error)
REM Only has 1 Yes/No option named "3 Parts"
REM #endregion
REM --------------------------------
REM #region Helper Functions
REM --------------------------------
Function GetRevlative(path, relativeFrom)
Dim rLen = Len(relativeFrom)
Dim rel = InStr(1, path "\" + relativeFrom + "\")
Dim rv
If Not rel Then
rel = InStr(1, path "/" + relativeFrom + "/")
EndIf
If rel Then
rv = SubString(path, rel + rLen + 2, 0)
Else
rv = path
EndIf
Return rv
EndFunction
Function LoadTextData(txtPath)
OptionList = new Array()
targetOption = ""
targetNumber = 0
object fileRef = new file(txtPath, FORINPUT + ISTEXT)
If (fileRef.IsOpen) Then
Dim line = fileRef.ReadLine()
Dim lineLength = Len(line)
fileRef.Close()
Dim i = 0, temp = "", charNext = ""
For i=1 To lineLength
charNext = SubString(line, i, i)
If (charNext = "|") Then
If (targetNumber = 0) Then
targetNumber = Number(temp)
Else
If (targetOption = "") Then
targetOption = temp
Else
OptionList.Add(temp)
EndIf
EndIf
temp = ""
ElseIf (i = lineLength) Then
temp = temp + charNext
OptionList.Add(temp)
Else
temp = temp + charNext
EndIf
Next i
EndIf
EndFunction
Function TABM(qty)
Dim tabs = ""
Dim tc
for tc = 1 to qty
tabs = tabs + constTAB
Next tc
return tabs
End Function
Function Unquote(value)
Dim k, cchar, resval = ""
For k = 1 To Len(value)
Dim cchar = Substring(value, k, k)
If (cchar <> constQT) Then
resval = resval + cchar
EndIf
Next k
return resval
EndFunction
Function JVAL(key, value)
Return constQT + key + constQT + ": " + constQT + value + constQT
End Function
Function JKEY(key, tabcount)
Return TABM(tabcount) + constQT + key + constQT + ": "
End Function
Function JOBJ(key, tabcount)
Return TABM(tabcount) + constQT + key + constQT + ": "
End Function
Function JLINE(key, value, tabcount)
Return TABM(tabcount) + JVAL(key, value) + "," + CRLF()
End Function
Function QUOTE(key, suffix)
Return constQT + key + constQT + suffix
End Function
Function CRLF()
Return constLF
End Function
REM #endregion
REM --------------------------------
REM #region Actual work
REM --------------------------------
Dim scanner as FILELOCATOR
scanner.Scan(root, "*.itm", True, False)
Task.BeginProgress(scanner.filecount)
Dim lp
For lp = 1 to scanner.filecount
Dim ITM as ITEMSTRUCT
Dim filePath = scanner.file[lp]
Dim fileName = GetFileName(filePath)
Dim textPath = SubString(filePath, 1, -4)
Dim index, cc
task.message = fileName
LoadTextData(textPath + ".txt")
Dim result
If (OptionList.Count = 0) Then
REM Static, textPath must not have existed
IF ITM.load(filePath) Then
result = "{" + CRLF()
result = result + JLINE("cid", ITM.CID, 1)
If (targetOption = "") Then
result = result + JLINE("option", "none", 1)
Else
result = result + JLINE("option", targetOption, 1)
EndIf
result = result + JKEY("values", 1) + "[" + CRLF()
result = result + TABM(2) + "{" + CRLF()
result = result + JLINE("active", "*default*", 3)
result = result + JKEY("dims", 3) + "[ "
For index = 1 To ITM.Dims
If (index = ITM.Dims) Then
result = result + QUOTE(ITM.Dim[index].Name, " ]," + CRLF())
Else
result = result + QUOTE(ITM.Dim[index].Name, ", ")
EndIf
Next index
if (ITM.Dims = 0) Then
result = result + "]," + CRLF()
EndIf
result = result + JKEY("options", 3) + "[ "
For index = 1 To ITM.Options
If (index = ITM.Options) Then
result = result + QUOTE(ITM.Option[index].Name, " ]" + CRLF())
Else
result = result + QUOTE(ITM.Option[index].Name, ", ")
EndIf
Next index
if (ITM.Options = 0) Then
result = result + "]" + CRLF()
EndIf
result = result + TABM(2) + "}" + CRLF()
result = result + constTAB + "]" + CRLF()
result = result + "}"
EndIf
Else
result = "{" + CRLF()
Dim handled = False
For cc = 1 To OptionList.Count
IF ITM.load(filePath) Then
Dim actualTarget
dim tempName = ITM.Option[targetNumber].Name
If (ITM.Option[targetNumber].Name = targetOption) Then
actualTarget = targetNumber
Else
actualTarget = targetOption
EndIf
If (handled = False) Then
result = result + JLINE("cid", ITM.CID, 1)
If (targetOption = "") Then
result = result + JLINE("option", "none", 1)
Else
If (ITM.Option[actualTarget] = Null) Then
result = result + JLINE("option", "error", 1)
Else
result = result + JLINE("option", targetOption, 1)
EndIf
EndIf
result = result + JKEY("values", 1) + "[" + CRLF()
handled = True
EndIf
If (ITM.Option[actualTarget] = Null) Then
Skipped = Skipped + ITM.CID + "|"
Else
ITM.Option[actualTarget].Value = OptionList[cc]
EndIf
ITM.Update()
result = result + TABM(2) + "{" + CRLF()
result = result + JLINE("active", Unquote(OptionList[cc]), 3)
result = result + JKEY("dims", 3) + "[ "
For index = 1 To ITM.Dims
If (index = ITM.Dims) Then
result = result + QUOTE(ITM.Dim[index].Name, " ]," + CRLF())
Else
result = result + QUOTE(ITM.Dim[index].Name, ", ")
EndIf
Next index
if (ITM.Dims = 0) Then
result = result + "]," + CRLF()
EndIf
result = result + JKEY("options", 3) + "[ "
For index = 1 To ITM.Options
If (index = ITM.Options) Then
result = result + QUOTE(ITM.Option[index].Name, " ]" + CRLF())
Else
result = result + QUOTE(ITM.Option[index].Name, ", ")
EndIf
Next index
if (ITM.Options = 0) Then
result = result + "]" + CRLF()
EndIf
If (cc < OptionList.Count) Then
result = result + TABM(2) + "}," + CRLF()
Else
result = result + TABM(2) + "}" + CRLF()
EndIf
EndIf
Next cc
result = result + constTAB + "]" + CRLF()
result = result + "}"
EndIf
object fileWrite = new file(textPath + ".json", FOROUTPUT + ISTEXT)
If (fileWrite.IsOpen) Then
fileWrite.WriteLine(result)
fileWrite.Close()
EndIf
Next lp
object skipWrite = new file(root + "/ERRORS.txt", FOROUTPUT + ISTEXT)
If (skipWrite.IsOpen) Then
skipWrite.WriteLine(Skipped)
skipWrite.Close()
EndIf
Task.EndProgress()
REM #endregion