Copy link to clipboard
Copied
I need a script or action or rtfm-quote that renames all artboards (may be selected only, but I see no use of it) with default pattern ('Artboard X'), where X is an actual number of artboard.
I'm a bit tired that after rearranging order of arboards their labels don't correspond with numbers.
function renameArtboards(){
var docRef = app.activeDocument;
var aB = docRef.artboards;
for(var a=0;a<aB.length;a++){
var curAB = aB;
curAB.name = "Artboard " + [a+1];
}
}
renameArtboards();
Copy link to clipboard
Copied
Hellow my friend!
carloscanto‌ wrote the script that solves your problem:
#target illustrator
// script.name = UI_insertPageNumbers.jsx; // works with CS4 & CS5
// script description = Inserts page numbers (or any other text) to all artboards in the active document;
// script.required = at least one open document
// script.parent = CarlosCanto // 11/14/11;
// script.elegant = false;
// Notes: The script creates a new layer (Page Numbers) then adds a text frame per Artboard that act as footer or header text.
// Its primary function is to insert Page Numbers, but it could be used to insert any other kind of information.
if (app.documents.length > 0) // continue if there's at leat one document open
{
// start building User Interface
var win = new Window("dialog","MTools - Insert Page Numbers");
var panelMargins = win.add("panel", undefined, "Margins");
var lblMargins = panelMargins.add("statictext",undefined,"How far from the edge:");
var txtMargins = panelMargins.add("edittext",undefined, 0.25);
var lblUnits = panelMargins.add("statictext",undefined,"inches");
var panelLocation = win.add("panel", undefined, "Location");
var radTop = panelLocation.add("radiobutton",undefined,"Top");
var radBottom = panelLocation.add("radiobutton",undefined, "Bottom");
var panelAlignment = win.add("panel", undefined, "Alignment");
var radLeft = panelAlignment.add("radiobutton",undefined,"Left");
var radCenter = panelAlignment.add("radiobutton",undefined, "Center");
var radRight = panelAlignment.add("radiobutton",undefined, "Right");
var panelFooter = win.add("panel", undefined, "Text to insert");
var grpPages = panelFooter.add("group");
var btnPage = grpPages.add("button",undefined,"Insert Page");
var btnPages = grpPages.add("button",undefined,"Insert Pages");
var txtFooter = panelFooter.add("edittext",undefined, "[Type text to insert here]");
var btnOk = win.add("button", undefined, "Ok");
radRight.value = radBottom.value = true;
win.alignChildren = panelFooter.alignChildren = "fill";
panelMargins.spacing = 3;
panelMargins.orientation = panelLocation.orientation = panelAlignment.orientation = "row";
win.helpTip = "Coded by CarlosCanto";
btnPage.helpTip = "Adds *page* keyword, it represents a single page";
btnPages.helpTip = "Adds *pages* keyword, it represents total number of pages";
txtFooter.helpTip = "Type \r\t'Page *page* of *pages*' \rto get \r\t'Page 1 of 3' \rfor example";
//-----------------------------------------------------------------------------------------
btnOk.onClick = function(){
doSomething(); // call main function
win.close(); // close when done
}
//-----------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------
btnPage.onClick = function(){
footer("*page*");
}
//-----------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------
btnPages.onClick = function(){
footer("*pages*");
}
//-----------------------------------------------------------------------------------------
win.center();
win.show();
//-----------------------------------------------------------------------------------------
function footer (page) //
{
txtFooter.text = txtFooter.text + page;
}
function doSomething()
{
//alert("I'm doing something");
var idoc = app.activeDocument;
var ilayer = idoc.layers.add();
ilayer.name = "Page Numbers";
var pages = idoc.artboards.length; // number of artboards
var footerPages = (txtFooter.text).replace("*pages*",pages); // replace the "*pages*" keyword with the actual number fo pages (artboards)
var margins = Number(txtMargins.text)*72; // get margins in points
//$.writeln(margins);
for (i = 0; i<idoc.artboards.length; i++) // loop thru all artboards, and add input text from UI
{
footerPage = footerPages.replace("*page*",i+1); // replace "*page*" keyword with the actual page Number
var itext = ilayer.textFrames.add();
itext.contents = footerPage; //"page 1 of 1";
var fontSize = itext.textRange.characterAttributes.size;
var activeAB = idoc.artboards;
var iartBounds = activeAB.artboardRect;
var ableft = iartBounds[0]+margins;
var abtop = iartBounds[1]-margins;
var abright = iartBounds[2]-margins;
var abbottom = iartBounds[3]+margins+fontSize;
var abcenter = ableft+(abright-ableft)/2;
if (radRight.value == true)
{
//var msg = "right";
itext.left = abright;
itext.textRange.paragraphAttributes.justification = Justification.RIGHT;
}
else if (radCenter.value == true)
{
//var msg = "center";
itext.left = abcenter;
itext.textRange.paragraphAttributes.justification = Justification.CENTER;
}
else
{
//var msg = "Left";
itext.left = ableft;
itext.textRange.paragraphAttributes.justification = Justification.LEFT;
}
if (radTop.value == true)
{
var msg = "top";
itext.top = abtop;
}
else
{
var msg = "bottom";
itext.top = abbottom;
}
} // end for loop thru all artboards
} // end function doSomething();
}
else
{
alert ("there's no open documents");
}
or visit the link
Copy link to clipboard
Copied
This is not quite what I wanted.
I guess my English is to blame.
I'm speaking of artboard names, seen as labels in top left corner when Artboard tool is active, or as list items in Artboards palete.
For example, I have created 4 artboards:
01 - Artboard 1
02 - Artboard 2
03 - Artboard 3
04 - Artboard 4
These are their names by default, right?
Then I rearrange them by dragging in pallete (or delete one from the middle); now they look like these:
01 - Artboard 3
02 - Artboard 1
03 - Artboard 2
04 - Artboard 4
I want something that will rename 'Artboard X' to their actula numbers, so they will look like they are just created.
I think even better would be something similar that illustrator-scripts/batchTextEdit.jsx at master · shspage/illustrator-scripts · GitHub does.
Copy link to clipboard
Copied
I understand, I'll try and answer as soon as a solution.
hug
Copy link to clipboard
Copied
function renameArtboards(){
var docRef = app.activeDocument;
var aB = docRef.artboards;
for(var a=0;a<aB.length;a++){
var curAB = aB;
curAB.name = "Artboard " + [a+1];
}
}
renameArtboards();
Copy link to clipboard
Copied
Good #williamadowling.
It was missing just a } at the end.
function renameArtboards(){
var docRef = app.activeDocument;
var aB = docRef.artboards;
for(var a=0;a<aB.length;a++){
var curAB = aB;
curAB.name = "00" + [a+1];
}
}
renameArtboards();
Copy link to clipboard
Copied
woops. you are totally right. i just typed that out here in the editor and didn't even test it. I hope that works for you. 😃
Copy link to clipboard
Copied
And it's working.
I only edited this line to get correct name:
curAB.name = "Artboard " + [a+1];
When I look at the code, I understand everything, but I couldn't have done it myself for unknown reason. It might be my imperfect knowledge of syntax or DOM, I guess.
Thanks!
Copy link to clipboard
Copied
You can put anything in the string that precedes the number. If you prefer the number in front just reverse.
cruAB.name = [a+1] + "Artboard";
hug
Copy link to clipboard
Copied
That's correct. You can concatenate essentially anything you want to the name of the artboard. And you can do so in any order.
Do post back here if you have any questions and we'll be glad to help.
Copy link to clipboard
Copied
Well, the script, as I said before, is working, but only by half.
It really does rename artboards, so their names looks like 'Artboard 1' and counting forth.
By when things go to the export, resulting tif-files have names like these:
exportedfile_Artboard 1.tif
while the result needed is more like:
exportedfile-01.tif
The problem is when I delete some of the artboards, don't use script, and then export stuff, I get order with gaps:
exportedfile-02.tif
exportedfile-04.tif
exportedfile-12.tif
and so on.
The script was intended to restore that order, resetting it rather than actual renaming.
It seems that artboard 'name' could be undefined, and the order is hidden somewhere deeper.
Copy link to clipboard
Copied
Just change the artboard naming convention from "Artboard " + [index] to simply [index]. For example:
function renameArtboards(){
var docRef = app.activeDocument;
var aB = docRef.artboards;
for(var a=0;a<aB.length;a++){
var curAB = aB;
if(a<10){
curAB.name = "'0" + (a+1) + "'"; // this line makes sure there's a 0 in front of single digit numbers (eg. exportedfile-02.tif)
}else{
curAB.name = "'" + (a+1) + "'";
}
}
renameArtboards();
Copy link to clipboard
Copied
Hi williamadowling‌,
how about
// regards pixxxel schubser
var aDoc = app.activeDocument;
var aB = aDoc.artboards;
function renameArtboards() {
for( i=0; i<aB.length; i++) {
var curAB = aB;
curAB.name = "Artboard " + (i+1).toString().replace(/^.$/, "0" + (i+1));
}
}
renameArtboards();
- without if else
Have fun
Copy link to clipboard
Copied
I'm sure that would work. Although i honestly don't know what's going on inside that replace method (or any replace methods for that matter..) i need to spend some time studying up on that.
Copy link to clipboard
Copied
google Regex.
very handy to have an understanding of.
/ / these enclose the Regular expression
^ says to match at start of string
$ says to match end of string
. says match any single char
in essence it is:
if(i.length == 1) {
curAB.name = "Artboard 0" + i;
}else{
curAB.name = "Artboard " + i;
}
so out put would go:
Artboard 01
Artboard 02
...
Artboard 09
Artboard 10
...
Copy link to clipboard
Copied
Well, nobody noticed the difference.
This one has undercore after filename — exportedfile_Artboard 1.tif
This one, exported from unrenamed artboard, has not, it has hypen instead — exportedfile-01.tif
Even if get rid of 'Artboard' it will still differ:
exportedfile-01.tif vs exportedfile_01.tif
I have a whole pipeline for editing these files after exporting, so this change is very irritating, becuase I have both renamed and unrenamed ways to work with, manually choose the set of scripts, put changes in both sets and so on.
So the problem turn out to be not about renaming artboards, but resetting numbering order. And I'm very suspicious it's not possible. Cruel world!
Copy link to clipboard
Copied
Well I'm out of ideas. Sorry friend. It appears that once you name an artboard, you forever lose the hyphen and you always get an underscore. Unless someone knows how to remove any associated name from an artboard (and just set it back to the default generic name), i've got nothing. Sorry.
Copy link to clipboard
Copied
that's exactly what happens, unnamed Artboards just append Dash/Index at export time, while named Artboards append Underscore/ArtboardName...
so your options are
1. rename all your artboards to 01, 02, etc to get filename_01, filename_02, etc
2. rename your files after exporting to get standard filename-01, filename-02, etc
Copy link to clipboard
Copied
Copy link to clipboard
Copied
There's a missing } in the correct answer. Add one to the line before last. I.e it should look like this
function renameArtboards(){
var docRef = app.activeDocument;
var aB = docRef.artboards;
for(var a=0; a<aB.length; a++){
var curAB = aB;
curAB.name = "Artboard " + [a+1];
}
}
renameArtboards();
Copy link to clipboard
Copied
I don't really know how to use this script. I opened the file and then used the script but nothing happened
Copy link to clipboard
Copied
The purpose of the script appears to be to match the number and name of the artboard, i.e. X - Artboard X. So try this:
var AB = app.activeDocument.artboards;
for(var i = 0; i < AB.length; i++){
AB[i].name = "Artboard " + (i + 1);
}
Copy link to clipboard
Copied
It really worked! Thank you so much. Is there an option that number coud be: 01, 02... 10, 11 instead of 01, 02...010, 011? (there's an extra zero) Greetings!
Copy link to clipboard
Copied
So total novice here - how do we use this code? I read to save as text file and rename to .jsx
I'm using text edit but only option is richtext?
any help these years later be epic!
Copy link to clipboard
Copied
So now I'm in script editor, but I'm getting the error below. Thanks again!