Skip to main content
karth80472045
Inspiring
February 13, 2016
Answered

script required

  • February 13, 2016
  • 5 replies
  • 2232 views

i have 100 groups in each group there are two strings named LXXX i have to replace first string by L01a and second string by L01b  likewise for second group i have to replace by L01c and L01d please help me how to code it. my idea is to copy all the strings to excel and i will rename it and i will automatically copy it. please help to write script.

This topic has been closed for replies.
Correct answer Qwertyfly___

You just need to test the contents of each textFrame before changing it


var txt = app.activeDocument.textFrames; 

var count = 0;

for(var i=0; i<txt.length; i++){

    if(txt.contents === "LXXX"){

        count++;

        var letter = toLetters(count); 

        txt.contents = "L01" + letter;

    }

 

 

function toLetters(num) { 

    "use strict"; 

    var mod = num % 26, 

        pow = num / 26 | 0, 

        out = mod ? String.fromCharCode(64 + mod) : (--pow, 'Z'); 

    return pow ? toLetters(pow) + out : out; 

}

5 replies

Participant
October 23, 2016

Have you successfully verified that "use strict" works?

I have not been able to create an minimalistic code snippet that generates an error with "use strinct" or "#strict on".

Figure I'm missing something obvious .

karth80472045
Inspiring
February 18, 2016

after reaching L09z  it should change to l10a like wise it should continue

Qwertyfly___
Legend
February 18, 2016

try this

var txt = app.activeDocument.textFrames;   

var count = 0;

for(var i=0; i<txt.length; i++){  

    if(txt.contents === "LXXX"){ 

        count++; 

        var letter = toLetters(count);

        txt.contents = "L" + letter; 

    } 

}   

   

   

function toLetters(num) {   

    "use strict";   

    var mod = num % 26,   

        pow = (num / 26 | 0)+1,   

        out = mod ? String.fromCharCode(64 + mod) : (--pow, 'Z'); 

        if(pow<10){pow = "0"+pow;}

    return pow ? pow + out : out;   

}

karth80472045
Inspiring
February 21, 2016

thanks a lot, suppose after running this script if it is ended at L12f then some object lxxx added means then it starts from L01a please write the separate script starting from there or just give the idea i will develop it

karth80472045
Inspiring
February 18, 2016

thanks a lot, last help is that after l01reaches lo1z It should change to lo2a please modify almost all are correct

karth80472045
Inspiring
February 17, 2016

thanks a lot, but in that it is changing all the things i want text with LXXX to be changed if u clearly see the image , u will see inside the circle lxxx will be present so i would like to change that character only

pixxxelschubser
Community Expert
Community Expert
February 17, 2016

karth80472045‌,

again:

Qwertyfly... schrieb:

… A sample file … would make this much simpler to do.

Regards

Silly-V
Legend
February 13, 2016

So do you know how javascript, or are you looking to do this in VB or Applescript?

karth80472045
Inspiring
February 14, 2016

i would like to do in java script please help me

Silly-V
Legend
February 14, 2016

Okay I can help!

So, are you saying that in each of your groups there's 2 text boxes?