Creating a project in KTM more efficiently

Sometimes always starting from scratch when creating projects with Kofax Transformation Modules can be quite exhausting. Especially if you come back from a customer workshop who wants to deal with probably a dozen different classes and subclasses. Creating them all manually can take a long time and – let’s face it – it is not really the most demanding task there is.

Fortunately, the result of such workshops already provides us with all the information required. Image that we were at a customer and did a thorough document analysis. As a result, we often receive a spreadsheet containing information about a certain document that has been analysed, its class and also several other information. I decided to save that spreadsheet in a CSV format as well which will become the data source for my script.

docworkshop

As you can see, that file contains one row for each document analysed, its class and the proper parent class.

Now the idea is simple: a script in an empty KTM project parses that CSV and creates a new class for each distinct value found with respect to a possible parent class.

First I’d need a helper method which will read the CSV file and return a collection of lines.


' reads an UTF-8 file with CRLF and returns a collection of lines that can later on be splitted
Public Function GetCSVLines(Path As String) As Variant
' requires an UTF-8 file with CRLF!

Dim fnum As Integer
Dim tmp As String
Dim wholeFile As String
Dim lines As Variant

fnum = FreeFile
Open Path For Input As fnum
wholeFile = Input$(LOF(fnum), fnum)
Close fnum

lines = Split(wholeFile, vbCrLf)
GetCSVLines = lines

End Function

Then, I call the following method once. I usually use the Batch_Open event.


Private Sub MakeClasses(theFile As String)

Dim theLines As Variant
Dim i As Integer
Dim classNames As Variant

theLines = GetCSVLines(theFile)

For i = 1 To UBound(theLines) ' ignore the header, that's why we start with 1
' the first column = the base class
' the second column = superclass, if any
classNames = Split(theLines(i), ",")
' check if the class already exists
If Project.ClassByName(classNames(0)) Is Nothing Then
Project.AddClass(classNames(0), classNames(1))
Else
Debug.Print "class already exists, skipping"
End If

Next

End Sub

The result is quite satisfying:

docHierarchy

Of course we are only scratching the surface here: you could automatically create locators and index fields as well, plus alter the properties. So, in theory, it would be possible to generate a whole project including classes, index fields, locators and even the validation form from a spreadsheet containing all the learnings from a customer workshop!