Inspiring
September 27, 2022
Answered
increasing the number only
- September 27, 2022
- 1 reply
- 1372 views
Greetings to all
I have a project with more than 200 names and these names contain a number
One of them is in the beginning of a line, in the middle of a line, or at the end of a line
i use this code
I use this code, but it works on a number only
I want it to work on text and number while preserving the text and increasing the number only
doc = app.activeDocument;
// the front document
var txtLayer = activeDocument.layers[0];
// obviously, the text layer if found
if (txtLayer) {
var num = txtLayer.textItem.contents.match(/\d+/)[0],
// find the numeric part
len = num.length,
// find the length of the numeric part
num = (parseInt(num,10)+1).toString();
// add 1 to that number
while (num.length < len) num = '0' + num;
// and adjust length if necessary so that e.g.
// 032 will not become 33 but it will become 033
//txtLayer.textItem.contents = '#' + num;
txtLayer.textItem.contents = num;
};
