Automatically change all number by some factor


hi,

 

i've been trying make javascript cs3 can in following situation:

all figure numbers must chnage "+1". example "fig 2" changes "fig 3".

 

1) there way using grep?

 

2) thought there isn't, tried script, got stuck no results. guys know of existing script on subject? otherwise, can tell me did go wrong?

 

thanks lot,

ola

 

 

mydoc = app.activedocument;


app.findgreppreferences = nothingenum.nothing;
app.changegreppreferences = nothingenum.nothing;
app.findgreppreferences.findwhat = "fig \\d+";
app.findchangegrepoptions.includefootnotes = true;
app.findchangegrepoptions.includehiddenlayers = false;
app.findchangegrepoptions.includelockedlayersforfind = false;
app.findchangegrepoptions.includelockedstoriesforfind = false;
app.findchangegrepoptions.includemasterpages = false;

var myfounditems = mydoc.findgrep();
var mydoneitems = [];

fig = "fig "

for (i=myfounditems.length; i>0; i--)
{
string = myfounditems[i].contents;
if (string
num = string.slice(5, string.length);
newnum = num*1;
newnum = newnum-1;
newnum = newnum+"";
newstring = fig+newnum;

app.findgreppreferences = nothingenum.nothing;
app.changegreppreferences = nothingenum.nothing;
app.findgreppreferences.findwhat = "fig "+string;
app.findgreppreferences.changeto = "fig "+newstring;


}

"ginm" -- grep not magic :-)

 

your script looks should work reason nothing cannot "insert" new string using grep. stating

 

myfounditems[i].contents = newstring;

 

should work. (i think could make work grep thing, it'd replace 'fig 2' 'fig 3' , 'fig 3' 'fig 4'.)

perhaps should test line

 

num = string.slice(5, string.length);

as -- js starts counting @ 0, number after "fig " starts @ position 4. i'm not sure slice command think got wrong.



More discussions in InDesign Scripting


adobe

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???