I need to Invoke the python script for Notepad++ only after completion of other steps which are automated.Can this script be invoked from a batch file.Will it always require manual intervention?
I tried executing the script from command line Python.exe, but this did not work as it does not recognize the Notepad++ specific objects such as BUFFERENCODING. Can the script be invoked from .Net code?
Below is the script that changes the encoding of all files to UTF-8 in the folder specified:
iffile[-4:].lower()=='.csv':
console.write("file is csv\n")notepad.open(filePath)textToWrite="File Current Encoding: "+str(filePath[filePath.rfind("\\")+1:])+":"+str(notepad.getEncoding())+"\n"logFile.write(textToWrite)console.write(textToWrite)notepad.runMenuCommand("Japanese","Shift-JIS")notepad.runMenuCommand("Encoding","Convert to UTF-8 without BOM")textToWrite="File Encoding Changed: "+encodingMap.get(notepad.getEncoding(),'UNKNOWN')+"\n"editor.replace('\\"','"')logFile.write(textToWrite)notepad.save()foundCount+=1notepad.close()
Hi Veekshita,
If I understand you correctly, you want to run some automated process and when that is finished, run your N++ script to change the UTF-8 encoding for all files in the folder specified?
I'd agree with Claudia that you might try launching the automated process from within you N++ script and then waiting for it to finish before proceeding with the conversion. However, sometimes that is just not possible...
A second solution that might work for you invloves the ActiveX plugin. It will create a COM wrapper around N++ that allows you to automate it from an external program. You will need administrative access on the computer to register the ActiveX plugin's DLL, but once you do that you should be able to invoke your N++ Python Script from just about any other scripting or programming language (using the INppMenuItem.execute method)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
How do you start the batch? From commandline or within notepad++?
Did you consider running the batch using python script plugin?
Or do you use nppexec to run the batch.
In general, the notepad++ sprecific objects are only accessible within a running notepad++ instance.
Cheers
Claudia
Last edit: CFrank 2017-05-23
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I need to Invoke the python script for Notepad++ only after completion of other steps which are automated.Can this script be invoked from a batch file.Will it always require manual intervention?
I tried executing the script from command line Python.exe, but this did not work as it does not recognize the Notepad++ specific objects such as BUFFERENCODING. Can the script be invoked from .Net code?
Below is the script that changes the encoding of all files to UTF-8 in the folder specified:
import os;
import sys;
import re;
User Defined Variables
filePathSrc='D:\'
logFile = open(filePathSrc+ "\EncodingChange.log", "w")
foundCount = 0
encodingMap = { BUFFERENCODING.COOKIE : 'UTF-8 without BOM', BUFFERENCODING.ENC8BIT : 'ANSI', BUFFERENCODING.UTF8: 'UTF-8' }
textToWrite = "Starting Script...\n"
console.write(textToWrite)
logFile.write(textToWrite)
for root, subFolders, files in os.walk(filePathSrc): # searches file path recursively
textToWrite = "Scanning: " +root + "\n"
console.write(textToWrite)
logFile.write(textToWrite)
for file in files:
filePath = os.path.join(root,file)
textToWrite = "File being processed: " +filePath+ "\n"
console.write(textToWrite)
logFile.write(textToWrite)
textToWrite = "Program Completed successfully!\n"
console.write(textToWrite)
logFile.write(textToWrite)
textToWrite="File_Count:"+str(foundCount)+"\n"
logFile.write(textToWrite)
logFile.close()
Hi Veekshita,
If I understand you correctly, you want to run some automated process and when that is finished, run your N++ script to change the UTF-8 encoding for all files in the folder specified?
I'd agree with Claudia that you might try launching the automated process from within you N++ script and then waiting for it to finish before proceeding with the conversion. However, sometimes that is just not possible...
A second solution that might work for you invloves the ActiveX plugin. It will create a COM wrapper around N++ that allows you to automate it from an external program. You will need administrative access on the computer to register the ActiveX plugin's DLL, but once you do that you should be able to invoke your N++ Python Script from just about any other scripting or programming language (using the INppMenuItem.execute method)
How do you start the batch? From commandline or within notepad++?
Did you consider running the batch using python script plugin?
Or do you use nppexec to run the batch.
In general, the notepad++ sprecific objects are only accessible within a running notepad++ instance.
Cheers
Claudia
Last edit: CFrank 2017-05-23