'
Sub CATMain()
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "Text files|*.txt"
intReturn = objDialog.ShowOpen
' Set objDialog = CreateObject("SAFRCFileDlg.FileOpen")
' intReturn = objDialog.OpenFileOpenDlg
If intReturn Then
szOpenFileName = objDialog.FileName
szSaveFileName = replace(szOpenFileName, ".txt", ".csv")
szCatalogFileName = replace(szOpenFileName, ".txt", ".catalog")
If CatiaCatalog2Csv(szOpenFileName, szSaveFileName) = False Then Exit Sub
If MsgBox(szSaveFileName & " is created. Do you want to open it?", vbYesNo) = vbYes Then
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "notepad.exe " & szSaveFileName
End If
'Creates a catalog document
Dim Catlg 'As Document
Set Catlg = CATIA.Documents.Add("CatalogDocument")
Catlg.CreateCatalogFromcsv szSaveFileName, szCatalogFileName
Catlg.Close
End If
End Sub
Function CatiaCatalog2Csv(rdFile, svFile)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set inFile = objFSO.OpenTextFile(rdFile)
Set outFile = objFSO.CreateTextFile(svFile)
bFirst = True
bChap = True
keyword = ""
types = ""
Values = ""
Do While Not inFile.AtEndOfStream
Line = inFile.ReadLine
If Left(Line, 8) = "Chapitre" Then
sVal = Trim(Right(Line, Len(Line) - 8))
If bFirst Then
bFirst = False
Else
If Len(keyword) > 0 Then
outFile.WriteLine ("Keywords" & keyword)
outFile.WriteLine ("Types" & types)
keyword = ""
types = ""
End If
If Len(Values) > 0 Then
outFile.WriteLine (Values)
Values = ""
End If
outFile.WriteLine ("END")
If Left(sVal, 3) = "Mfg" Then
bChap = False
outFile.Write ("END")
Else
bChap = True
End If
End If
outFile.WriteLine ("CHAPTER," & sVal)
End If
If Left(Line, 7) = "Keyword" Then
sp = InStr(1, Line, "(type=")
ep = InStr(1, Line, ")")
If sp > 0 Then
sVal = Trim(Mid(Line, 8, sp - 8))
keyword = keyword & "," & sVal
sVal = Trim(Mid(Line, sp + 7, ep - sp - 7))
types = types & "," & sVal
End If
sp = InStr(1, Line, "(value =")
If Not bChap And sp > 0 Then
sVal = Trim(Mid(Line, sp + 8, ep - sp - 8))
If LCase(sVal) = "true" Or LCase(sVal) = "false" Then
sVal = UCase(sVal)
End If
Values = Values & "," & sVal
End If
End If
If Left(Line, 17) = "Description Name:" Then
sVal = Trim(Right(Line, Len(Line) - 17))
If Len(keyword) > 0 Then
outFile.WriteLine ("Keywords" & keyword)
outFile.WriteLine ("Types" & types)
keyword = ""
types = ""
End If
If Len(Values) > 0 Then
outFile.WriteLine (Values)
Values = ""
End If
If bChap Then
outFile.WriteLine (sVal & "," & sVal)
End If
End If
Loop
If Len(keyword) > 0 Then
outFile.WriteLine ("Keywords" & keyword)
outFile.WriteLine ("Types" & types)
End If
If Len(Values) > 0 Then
outFile.WriteLine (Values)
End If
outFile.WriteLine ("END")
'outFile.Close()
CatiaCatalog2Csv = objFSO.FileExists(svFile)
End Function