Indenting TI processes

Introduction

[rant mode=ON]

A longstanding cause of annoyance among TM1 developers and admins, is that the Turbo Integrator interface is euhm… archaic. It is not the flexible, good-looking editor one might/can expect nowadays.

[rant mode=OFF]

How about writing a bit of code ourselves for basic functionalities? I know that there is a goodlooking TI editor, but it is not part of TM1 and it is not priceless.

If you follow along this article and the code therein, you will learn…:

  • how to use TI to execute VBScript files
  • that you can specify parameters to the VBS
  • some nice tricks to speed up code execution and write less code

In the end, a few lines of code will indent your full TI process!

Turbo Integrator will help us

Create a new process and give it a meaningful name. Add 2 parameters:

ParameterTypeDefault ValuePrompt Question
pProcessNameStringWhich TI process do you want to indent ?
pSpacesNumeric5How many spaces do you want to indent ?

Add this bit of code to the Advanced > Prolog tab of the process:

# Wim Gielis # http://www.wimgielis.com
##### # Indenting the code of a TI process # 05/04/10 #####
IF(FILEEXISTS(pProcessName | '.pro')=1); EXECUTECOMMAND('cscript indenting.vbs "' | pProcessName | '"' | NUMBERTOSTRING(pSpaces),1); ENDIF;

Wait! Save this process but do not execute this yet since we are still missing the vbs file. Create a text file called indenting.vbs in your TM1 Database directory. It could also be elsewhere but then you need to go adding (hard-coded) path locations. These are the contents for the vbs file:

' Wim Gielis ' http://www.wimgielis.com
''''' ' Custom VBScript code to indent TI process code ' 05/04/10 '''''
'add extra constructs where you want to increase 'or decrease indentation. Separate with #'s.
Const sIndentingBegin = "#IF#WHILE#" Const sIndentingEnd = "#ENDIF;#END;#" Dim sTrimmedLine, iIndent, ArgObj, c0 Set ArgObj = WScript.Arguments Set c0 = CreateObject("scripting.filesystemobject") 'read in the original process code sq = Split(c0.OpenTextfile(ArgObj(0) & ".pro").ReadAll, vbCrLf) 'revise the process code For l = 0 To UBound(sq) sTrimmedLine = Trim(sq(l)) If Left(sTrimmedLine,2) & "^" & Right(sTrimmedLine,6) <> "IF^ENDIF;" Then If InStr(sIndentingEnd, "#" & sTrimmedLine & "#") Then iIndent = iIndent - 1 End If End If sq(l) = Space(ArgObj(1) * iIndent) & sTrimmedLine If Left(sTrimmedLine,2) & "^" & Right(sTrimmedLine,6) <> "IF^ENDIF;" Then If InStr(sIndentingBegin, "#" & Split(sTrimmedLine & "(", "(")(0) & "#") Then iIndent = iIndent + 1 End If End If Next 'output the revised process code c0.CreateTextfile(ArgObj(0) & "_Indented.pro").Write Join(sq, vbCrLf)

Important remarks

  • The VBScript code creates a file with the same name as the TI process, but appends the word ‘_Indented’ to it. The code will overwrite a file if it already exists.
  • You can now copy-paste the indented code in you own TI process. Alternatively, stop the TM1 service of your TM1 Server, rename files, and start the service again.
  • As mentioned in the commentary lines, you can add more functions where you want to indent. See on top of the code.
  • ArgObj is used to ask what parameters we supplied to the VBS file.

Have fun with this code!




Homepage

Section contents

About Wim

Wim Gielis is a Business Intelligence consultant and Excel expert

Other links