Skip to main content
Known Participant
July 9, 2020
Answered

Artboard name

  • July 9, 2020
  • 2 replies
  • 1466 views

Hello,

Do you have script for renaming artboard?

 

1. Rename artboard for Front side and Back side:

Artboard 1: Front

Artboard 2: Back

and placed it to the TOP LEFT

 

 

2. This is only 6 artboard for example, do you have shortcut for this?

I'm doing this by renaming artboard 1 by 1

then typing it in artboard 1 by 1.

 

S1F = Sheet 1 Front

S1B = Sheet 1 Back

 

 

thank you

 

This topic has been closed for replies.
Correct answer Charu Rajput

Hi,

The error that you getting S is undefined because S should be used inside the quotes "" like "S"

 

And for you latest requirement please try following snippet

 

function main() {
	var doc = app.activeDocument;
	artBoards = doc.artboards;
	var count = 1;
	for (var i = 1; i <= artBoards.length; i++) {
		var a = artBoards[i - 1];
		if (i % 2 == 0) { // even number
			a.name = "S" + (count) + "B";
			count++;
		}
		else { // odd number
			a.name = "S" + (count) + "F";
		}

		// Adding textframes
		artBoards.setActiveArtboardIndex(i - 1);
		var _textFrame = doc.textFrames.add();
		_textFrame.contents = a.name;
		_textFrame.top = a.artboardRect[1] - 10;
		_textFrame.left = a.artboardRect[0] + 10;
	}
}

main();

 

 

Let us know if it resolves your problem.

EDIT : Edit script to incorporate to show textframes for printing purpose with name of the artboard.

2 replies

pixxxelschubser
Community Expert
Community Expert
July 10, 2020

« Give a man a fish and he will be full. Teach him how to fish and he will never go hungry again. »

  attributed to Confucius

 

Try to learn the basics.

create a new layer

 

 

var doc = app.activeDocument;
var lay = doc.layers.add();

 

 

 

This layer is now the active layer.

add your text frame, create contents and lock the item

 

 

var tf = lay.textFrames.add();
tf.contents = "new contents";
tf.locked = true;

 

 

 

Try combining these lines of code with the script written by @Charu Rajput and ask later if you need further assistance.

 

Have fun

😉

Charu Rajput
Community Expert
Community Expert
July 9, 2020

Hi, for your first part try following snippet

function main() {
	var doc = app.activeDocument;
	doc.artboards[0].name = "FRONT";
	doc.artboards[1].name = "BACK";
}

main();

 

For your second part, try this one

function main() {
	var doc = app.activeDocument;
	artBoards = doc.artboards;
	var count = 1;
	for (var i = 1; i <= artBoards.length; i++) {
		var a = artBoards[i - 1];
		a.name = "S" + (count) + "F";
		if (i % 2 == 0)
			count++;
	}
}

main();

 

I would suggest to make a generalized version of the script to rename the artboards that will run for your workflow. For this you may need to think over the workflow of your work. But above version script will work for teh question of have asked.

 

Let us know if this help you.

 

Best regards
Known Participant
July 9, 2020

Thanks for your help,

 

You can disregard the first part. 

for the second part:

 

Can you make the 'odd number' of artboard (1,3,5,7,9 ~)

Artobard1: S1F

Artobard3: S2F

Artobard5: S3F

 

and 'even number' of artboard (2,4,6,8,10 ~)

Artobard2: S1B

Artobard4: S2B

Artobard6: S3B

 

Thank you

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
July 9, 2020

Hi,

The error that you getting S is undefined because S should be used inside the quotes "" like "S"

 

And for you latest requirement please try following snippet

 

function main() {
	var doc = app.activeDocument;
	artBoards = doc.artboards;
	var count = 1;
	for (var i = 1; i <= artBoards.length; i++) {
		var a = artBoards[i - 1];
		if (i % 2 == 0) { // even number
			a.name = "S" + (count) + "B";
			count++;
		}
		else { // odd number
			a.name = "S" + (count) + "F";
		}

		// Adding textframes
		artBoards.setActiveArtboardIndex(i - 1);
		var _textFrame = doc.textFrames.add();
		_textFrame.contents = a.name;
		_textFrame.top = a.artboardRect[1] - 10;
		_textFrame.left = a.artboardRect[0] + 10;
	}
}

main();

 

 

Let us know if it resolves your problem.

EDIT : Edit script to incorporate to show textframes for printing purpose with name of the artboard.

Best regards