Copy link to clipboard
Copied
Hey everybody
I'm working on a mapmaking project and I need to number element from approximately 1 to 100 on every map that i'm creating. I would like to automate the process and I'm losing a lot of time typing each number in a new text box for each element. Do you know if there is an easier way to do it or to create directly 100 text box from 1 to 100 ?
I tried to use the "script" option but Illustrator does not take in account when I type a new number, he just create 100 text box
Here you go. i hae no idea how to place the text frames.. but this will create them and fill the contents with integers from 1 to whatever number you pass as the function argument.
enjoy.
function makeLotsOfTextFrames(numFrames)
{
var doc = app.activeDocument;
for(var x=0,frame,yPos=0;x<numFrames;x++)
{
frame = doc.textFrames.add();
frame.contents = (x+1);
frame.top = yPos;
yPos += frame.height + 15;
}
}
makeLotsOfTextFrames(100);
Hi William,
there is a small typo in your code.
use this line
for(var x=0,frame,yPos=0;x<numFrames;x++)
and I would suggest better starting near the lower left corner. Then you could use for example something like that instead:
for(var x=0,frame,yPos=0-doc.height;x<numFrames;x++)
Copy link to clipboard
Copied
You can create circles around numbers with an effect.
I would start with a point text.
Select it with the selection tool
In the appearance panel add a new filland mode it below the "Characters"
Apply the effect > Convert to shape >Ellipse
Make it absolute size, so that it fits the highest number.
Create a graphic style
Copy link to clipboard
Copied
You may create a symbol library with the required numbers and reuse it whenever you need it.
Copy link to clipboard
Copied
Please show how your "numbers" looks like.
What "script" options did you use?
Copy link to clipboard
Copied
Here you go. i hae no idea how to place the text frames.. but this will create them and fill the contents with integers from 1 to whatever number you pass as the function argument.
enjoy.
function makeLotsOfTextFrames(numFrames)
{
var doc = app.activeDocument;
for(var x=0,frame,yPos=0;x<numFrames;x++)
{
frame = doc.textFrames.add();
frame.contents = (x+1);
frame.top = yPos;
yPos += frame.height + 15;
}
}
makeLotsOfTextFrames(100);
Copy link to clipboard
Copied
Hi William,
there is a small typo in your code.
use this line
for(var x=0,frame,yPos=0;x<numFrames;x++)
and I would suggest better starting near the lower left corner. Then you could use for example something like that instead:
for(var x=0,frame,yPos=0-doc.height;x<numFrames;x++)
Copy link to clipboard
Copied
ah crap. i noticed that typo too, but i guess i fixed it in the wrong version. (i typed it out in sublime, but then copied it to VS code to test it. looks like i fixed the bug in VS and then copied the function from sublime..)
Thanks!
Copy link to clipboard
Copied
Thanks for the answer ! It's exactly what I want to do and it works perfectly 😉
Copy link to clipboard
Copied
I'm trying to wrap my head around your for statement. I have never seen a for statement with so many parts....
Usually, I see for (let x=0;x<count;x++) {
do something }
and I can see those parts, but what is frame, yPos=0-doc.height and why is it in the for statement?
Just trying to understand, thanks for any explanation.
Copy link to clipboard
Copied
"but what is frame, yPos=0-doc.height and why is it in the for statement?"
They're just ordinary variable declarations or assignments, but done in the same line as the "for" initialiser, presumably for brevity.
for (var i = 0, x = 0; i < 3; i++) {
x = x + i;
}
alert( x ); // 0 + 0 + 1 + 2 = 3
It could have been done before the loop.
var x = 0;
for (var i = 0; i < 3; i++) {
x = x + i;
}
alert( x ); // 0 + 0 + 1 + 2 = 3
In fact, the "for" initialiser can be declared +/- initialised before the loop itself.
var i = 0, x = 0;
for (; i < 3; i++) {
x = x + i;
}
alert( x ); // 0 + 0 + 1 + 2 = 3
Copy link to clipboard
Copied
Now it's right.
😉