Create a number string in text box

New Here ,
Mar 31, 2021 Mar 31, 2021

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 

TOPICS
Scripting

Views

359

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct Answers

Adobe Community Professional , Mar 31, 2021 Mar 31, 2021
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);

Likes

Translate

Translate
Adobe Community Professional , Mar 31, 2021 Mar 31, 2021
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++)

Likes

Translate

Translate
Adobe Community Professional ,
Mar 31, 2021 Mar 31, 2021

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

You may create a symbol library with the required numbers and reuse it whenever you need it.

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

Please show how your "numbers" looks like.
What "script" options did you use?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 31, 2021 Mar 31, 2021

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);

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 31, 2021 Mar 31, 2021

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++)

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 31, 2021 Mar 31, 2021

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!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

Thanks for the answer ! It's exactly what I want to do and it works perfectly 😉

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 23, 2021 Apr 23, 2021

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 24, 2021 Apr 24, 2021

Copy link to clipboard

Copied

LATEST

"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

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

Now it's right.
😉

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines