Inspiring
October 13, 2022
Answered
automatic numbering of a part of the text
- October 13, 2022
- 1 reply
- 445 views
Welcome everyone
All thanks and appreciation to Charu Rajput
Because he helped me with this code
doc = app.activeDocument;
// the front document
var txtLayer = activeDocument.layers[0];
// obviously, the text layer if found
if (txtLayer) {
var _contents = txtLayer.textItem.contents;
var _oldNum = txtLayer.textItem.contents.match(/\d+/)[0],
// find the numeric part
len = _oldNum.length,
// find the length of the numeric part
_newNum = (parseInt(_oldNum, 10) + 1).toString();
// add 1 to that number
while (_newNum.length < len) _newNum = '0' + _newNum;
// 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 = _contents.replace(_oldNum, _newNum);
//Only use when you want replace all numbers in the line
// var _regEx = new RegExp(_oldNum, "g");
// txtLayer.textItem.contents = _contents.replace(_regEx, _newNum);
};But I faced a problem when I worked on a file with text that contains numbers and text as well as numbers
I want to number a certain part of the text while preserving the rest of the text and numbers
I have inserted a picture showing the shaded part that I want to number sequentially
I also included the code and a file to explain the whole idea

