使用Notepad ++自动脚本自动重新编号部分

时间:2015-07-30 17:18:45

标签: automation notepad++

我是一个很少编写脚本的modder。我需要一种方法来重新编号文件的以下部分:

        async void FriendListView_ItemTapped(object sender, ItemTappedEventArgs e)
        {           
            var el = e.Item as ProfileItem;
            SelectedItem = el;
            if (e.Item != null)
            {
               await Navigation.PushAsync(new FriendProfile(el));
            }
            ((ListView)sender).SelectedItem = null; // de-select the row
        }

该文件如下所示:

[Equipment 45]
 ..
 ..
 ..
 [Equipment 46]

 to 

 [Equipment 91]
 ..
 ..
 ..
 [Equipment 92]

并且必须像这样继续:

[Equipment 44]
ID=EqpEmblem1
NameDisplayable= Real men need no emblem
FunctionalType= EqFTypeCoating
EquipmentInterval= NULL, NULL
EquipmentSlotType=NULL
ExternalLinkName3D= NULL
Hitpoints= 10000
DamageDescription1= NULL,   0,  1,  0,  1,  1,  invulnerable,       0,  0,  NULL,   0,  1,  1

[Equipment 45]
ID=EqpEmblem2
NameDisplayable= U-1164
FunctionalType= EqFTypeCoating
EquipmentInterval= NULL, NULL
EquipmentSlotType=NULL
ExternalLinkName3D=data\Textures\TNormal\tex\U-1164.dds
Hitpoints= 10000
DamageDescription1= NULL,   0,  1,  0,  1,  1,  invulnerable,       0,  0,  NULL,   0,  1,  1

等等。

从[设备90]

简单地说出所有[设备n + 1]

所有与编码有关的都是学校中简单的Java内容和一些Elderscrolls脚本语言。

我想在记事本++中使用正则表达式搜索和替换或自动脚本插件

1 个答案:

答案 0 :(得分:0)

好的,我使用了以下python脚本:

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()

然后我在对话框中输入以下内容(光标,当然必须在需要重命名的文本上方1行,脚本按文字排列):

  

设备[0-9] +

     

设备\ i(91)

第一行找到包含&#34; Equipment&#34;的任何字符串。和数字 第二个替换了字符串&#34; Equipment&#34;并从91开始递增数字+1。

上帝保佑RegExp