Looking for the help of resident Python experts ;)
I am trying to set up a script to work with Techs file.
Specifically for example to move all techs gridX 1 position to the right.
I been searching the net and I found a script that does almost what I need, but need some work. The Python screen below is loaded into Notepad++ and run on the file you want to affect.
the current script can be used to find every instance of gridX value and replace it with a variable incremented in a loop at +1 value.
So first gridX value found becomes 1, 2nd becomes 2, etc.
Of course that's not exactly what I need - I need the script to read in the value and then increment it by 1, and then write it back.
From what I believe, there is only like 1 line that needs to be changed.
Would you please look at it for me?
thank you!
original code source:
http://stackoverflow.com/questions/1...ncrement-value
I am trying to set up a script to work with Techs file.
Specifically for example to move all techs gridX 1 position to the right.
I been searching the net and I found a script that does almost what I need, but need some work. The Python screen below is loaded into Notepad++ and run on the file you want to affect.
the current script can be used to find every instance of gridX value and replace it with a variable incremented in a loop at +1 value.
So first gridX value found becomes 1, 2nd becomes 2, etc.
Of course that's not exactly what I need - I need the script to read in the value and then increment it by 1, and then write it back.
From what I believe, there is only like 1 line that needs to be changed.
Would you please look at it for me?
thank you!
Code:
from Npp import *
import re, string
# First we'll start an undo action, then Ctrl-Z will undo the actions of the whole script
editor.beginUndoAction()
expression = notepad.prompt("Enter the search string on the first line, followed by Ctrl+Enter, \n" +
"followed by the replace string on second line",
"Incremental Search/Replace" ,
"")
expressionList = re.split(r"[\n\r]+", expression)
if len(expressionList) == 2:
foundCount = [0]
def incrementalReplace(parmReplaceStr,parmFoundCount):
varPatternI = r'\\i\((?P<starting>[0-9]+)\)'
varPatternIi = r'\\i'
varPatternISearch = re.search(varPatternI , parmReplaceStr)
if varPatternISearch != None:
varFoundCount = int(varPatternISearch.group('starting')) + parmFoundCount[0]
varReplaceString = re.sub(varPatternI ,str(varFoundCount ),parmReplaceStr)
elif re.search(varPatternIi, parmReplaceStr) != None:
varReplaceString = re.sub(varPatternIi,str(parmFoundCount[0]),parmReplaceStr)
parmFoundCount[0] = parmFoundCount[0] + 1
return varReplaceString
# Do a Python regular expression replace
editor.searchAnchor()
while editor.searchNext(0x00200000,expressionList[0]) != -1:
editor.replaceSel(incrementalReplace(expressionList[1],foundCount))
editor.lineDown()
editor.searchAnchor()
# End the undo action, so Ctrl-Z will undo the above two actions
editor.endUndoAction()
http://stackoverflow.com/questions/1...ncrement-value