Option Explicit Dim db, initResult, sheet, obj, cons, fso, output, total, seen, column, definition Set fso = CreateObject("Scripting.FileSystemObject") Set output = fso.CreateTextFile(WScript.Arguments(1), True, True) Set db = CreateObject("CMS.CeObjectDefsICDB") initResult = db.InitFromProjectFile(WScript.Arguments(2), "r", WScript.Arguments(0), WScript.Arguments(3), WScript.Arguments(4), "DxDesigner") output.WriteLine "{""kind"":""initialization"",""result"":" & V(initResult) & ",""read_only"":" & V(db.ReadOnly) & ",""project"":" & Q(db.PrjFile) & "}" If Not initResult Or LCase(db.PrjFile) <> LCase(WScript.Arguments(0)) Then output.Close WScript.Quit 3 End If total = 0 Set seen = CreateObject("Scripting.Dictionary") db.LoadAllDeferredPages For Each sheet In db.Sheets output.WriteLine "{""kind"":""sheet"",""name"":" & Q(sheet.Name) & "}" For Each column In sheet.Columns Set definition = column.ConstraintDef output.WriteLine "{""kind"":""definition"",""sheet"":" & Q(sheet.Name) & ",""name"":" & Q(definition.Name) & ",""title"":" & Q(definition.Title) & ",""description"":" & Q(definition.Description) & ",""data_type"":" & V(definition.DataType) & ",""unit_type"":" & V(definition.UnitType) & ",""unit"":" & V(definition.Unit) & ",""display_unit"":" & V(definition.DisplayUnit) & ",""default"":" & V(definition.Default) & "}" Next For Each obj In sheet.Objects DumpObject sheet.Name, obj Next Next output.WriteLine "{""kind"":""complete"",""count"":" & CStr(total) & ",""objects"":" & CStr(seen.Count) & "}" output.Close Set db = Nothing WScript.Echo "Constraints read: " & CStr(total) Sub DumpObject(sheetName, current) Dim key, constraint, child, children, actual, defaultValue, overridden, resolvedDefault, errorText, unitValue, def key = sheetName & vbTab & current.Level & vbTab & CStr(current.AthenaId) & vbTab & current.Name If seen.Exists(key) Then Exit Sub seen.Add key, True If seen.Count > 100000 Then WScript.Quit 4 For Each constraint In current.Constraints actual = "" : defaultValue = "" : overridden = "" : resolvedDefault = "" : errorText = "" unitValue = "" On Error Resume Next actual = constraint.Value If Err.Number <> 0 Then errorText = errorText & "Value: " & Err.Description & "; " : Err.Clear defaultValue = constraint.DefaultValue If Err.Number <> 0 Then errorText = errorText & "DefaultValue: " & Err.Description & "; " : Err.Clear overridden = constraint.IsOverridden If Err.Number <> 0 Then errorText = errorText & "IsOverridden: " & Err.Description & "; " : Err.Clear resolvedDefault = current.IsResolvedDefaultValue(constraint.Name, CStr(actual)) If Err.Number <> 0 Then errorText = errorText & "IsResolvedDefaultValue: " & Err.Description & "; " : Err.Clear Set def = constraint.ConstraintDef unitValue = constraint.GetStringValue(def.Unit) If Err.Number <> 0 Then errorText = errorText & "GetStringValue: " & Err.Description & "; " : Err.Clear On Error GoTo 0 output.WriteLine "{""kind"":""constraint"",""sheet"":" & Q(sheetName) & ",""object"":" & Q(current.Name) & ",""level"":" & Q(current.Level) & ",""athena_id"":" & Q(current.AthenaId) & ",""name"":" & Q(constraint.Name) & ",""value"":" & V(actual) & ",""default_value"":" & V(defaultValue) & ",""is_overridden"":" & V(overridden) & ",""equals_resolved_default"":" & V(resolvedDefault) & ",""value_in_definition_unit"":" & Q(unitValue) & ",""unit"":" & V(def.Unit) & ",""unit_type"":" & V(def.UnitType) & ",""error"":" & Q(errorText) & "}" total = total + 1 Next Set children = current.GetChildObjects If Not children Is Nothing Then For Each child In children DumpObject sheetName, child Next End If Set child = Nothing Set children = Nothing End Sub Function Q(value) Dim s If IsNull(value) Or IsEmpty(value) Then s = "" Else s = CStr(value) End If s = Replace(s, "\", "\\") s = Replace(s, Chr(34), "\" & Chr(34)) s = Replace(s, vbCr, "\r") s = Replace(s, vbLf, "\n") s = Replace(s, vbTab, "\t") Q = Chr(34) & s & Chr(34) End Function Function V(value) Select Case VarType(value) Case 0, 1 V = "null" Case 11 V = LCase(CStr(value)) Case 2, 3, 4, 5, 6, 14, 17 V = Replace(CStr(value), ",", ".") Case Else V = Q(value) End Select End Function