I'm trying to make a useful system to automatically increase numbers in selected text. For example, when I working in Zbrush on the project named "Example_character012" I have a folder with 23 files from "Example_character012_prj_01.zpr" to "Example_character012_prj_23.zpr". When I need to save next iteration I'm pressing "ctrl+s" and then regular saving screen opens in the last working directory with preselected filename text, in this scenario it would be "Example_character012_prj_23.zpr". I need to copy this text, select the last number(23) increase it by one, and past it all the text back to the text-field. In this case it would be "Example_character012_prj_24.zpr". This kind of script would be really useful in all kinds of scenario, mainly with saving in different programs. I tried to made it myself and come up with this:
^!Numpad1::
Sleep 100
Send ^c
Sleep 10
RegExMatch(clipboard,"(\d+)(?!.*\d)",Number)
NewNumber:=Number1+1
OldNumber:=NewNumber-1
Clipboard:=RegExReplace(clipboard, OldNumber, NewNumber)
Sleep 10
Send ^v
Sleep 10
Send +{Home}
Return
^!Numpad0::
Sleep 100
Send ^c
Sleep 10
RegExMatch(clipboard,"(\d+)(?!.*\d)",Number)
NewNumber:=Number1-1
OldNumber:=NewNumber+1
Clipboard:=RegExReplace(clipboard, OldNumber, NewNumber)
Sleep 10
Send ^v
Sleep 10
Send +{Home}
Return
Ctrl+alt+Num1 for increase and Ctrl+alt+Num0 for decrease. It's work fine with in the simplest scenario, but have significant problems I can't solve myself:
- It only works in english keyboard-layout. When I use it in russian layout - it puts "cv" instead of pasting(If I paste manually afterwards it put the correct text)
- Sometimes it increases not only the last number "Example_character012_prj_01.zpr" changing to "Example_character022_prj_02.zpr" instead of "Example_character012_prj_02.zpr"
- Zeros working incorrectly "Example_prj_09.zpr" changing to "Example_prj_010.zpr" instead of "Example_prj_10.zpr"
- After pasting it selects the whole line instead of only what just have been pasted
- If it's possible, it would be great to make it work without affecting clipboard at all.
- Sometimes some keys like "ctrl" just get stuck until being clicked manually for some reason.
Edit: Got some help at Autohotkey forums, current version of script below. Only questions 4 and 5 left.
^!Numpad1::
^!Numpad0::
Sleep 50
Send {Ctrl up}^{Ins}
Sleep 10
RegExMatch(Clipboard, "^(.*)(?=_)_(\d+)(\....)$", Match)
Len := StrLen(Match2)
if InStr(A_ThisHotkey, 1)
Match2++
else
Match2--
if (StrLen(Match2) < Len)
Match2 := Format("{:0" Len "}", Match2)
Clipboard := Match1 "_" Match2 Match3
Sleep 10
Send +{Ins}
Sleep 10
Send +{Home}
Return
(\d+)\.
? That should fix 2. and 3. – Fallenhero(\d+)(?:[^\d]*$)
– Fallenhero