Notepad++ and Python

Ideas and tips for enhancing your TM1 application
Post Reply
Wim Gielis
Posts: 2675
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.8
Excel Version: Microsoft 365
Location: Brussels, Belgium

Notepad++ and Python

Post by Wim Gielis » Sat Jul 18, 2020 9:49 am

Hi there,

As a good number of us are using Notepad++ for day to day operations (including rules and TI writing ;-)), I wanted to highlight that Notepad++ has a Python script plugin: You can also install it from the "Plugins manager".

This allows us to, for example, count all non-empty lines in all opened files (polish the code a bit):

Code: Select all

from Npp import *
import re
import ntpath

all_files_line_count = 0
s = "The total line count of all open files is:" + "\r\n"
tuple_list = notepad.getFiles()
for tuple in tuple_list:
    filename = tuple[0]
    if filename == "new  0": continue
    # parse the active editor's text
    this_files_line_count = 0
    Lines = re.split('\r\n|\r|\n|', editor.getText())
    for line in Lines:
        line = line[0:].strip()
        if line != "":
            this_files_line_count += 1
    all_files_line_count += this_files_line_count
    s = s + "\r\n" + ntpath.basename(filename) + "\t\t\t" + str(this_files_line_count)
notepad.messageBox(s + "\r\n\r\n" + "Total:" + "\t\t\t" + str(all_files_line_count), "", MESSAGEBOXFLAGS.OK)
Happy coding !

Best regards,

Wim Gielis

Excel Most Valuable Professional, 2011-2014 ==> 117 TM1 articles and a lot of custom code
Newest blog article: Avoid circular references

Post Reply