// Illustrator Script: Create Glyph Artboards with Descriptive Names
// This script creates individual artboards for each glyph in the given character set with descriptive names
// Character set
var charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"abcdefghijklmnopqrstuvwxyz" +
"1234567890" +
". , ; : "„'’‚…‹›»«*{}/-–_<>?!$@&+^#";
// Document setup
var doc = app.documents.add();
var artboardSize = 1024;
// Font settings
var fontSize = 800; // Starting font size, will be adjusted to fit
function findAvailableFont(preferredFonts) {
for (var i = 0; i < preferredFonts.length; i++) {
if (app.textFontInfo.get(preferredFonts[i]) != null) {
return app.textFontInfo.get(preferredFonts[i]);
}
}
// If no preferred fonts are found, return the first available font
return app.textFontInfo.get(app.fonts[0].name);
}
// List of preferred fonts (in order of preference)
var preferredFonts = ["Arial", "Helvetica", "Myriad Pro", "Tahoma", "Verdana"];
var selectedFont = findAvailableFont(preferredFonts);
// Create artboards and text for each character
for (var i = 0; i < charSet.length; i++) {
var glyph = charSet[i];
var glyphName = getGlyphName(glyph);
code
// Create new artboard
var artboardRect = [0, 0, artboardSize, artboardSize];
app.activeDocument.artboards.add();
var currentArtboard = app.activeDocument.artboards[app.activeDocument.artboards.length - 1];
currentArtboard.name = glyphName;
currentArtboard.artboardRect = artboardRect;
// Create text frame
var textFrame = app.activeDocument.textFrames.add();
textFrame.contents = glyph;
textFrame.textRange.characterAttributes.textFont = selectedFont;
textFrame.textRange.characterAttributes.size = fontSize;
// Center text
textFrame.left = (artboardSize - textFrame.width) / 2;
textFrame.top = (artboardSize - textFrame.height) / 2;
// Adjust font size to fit artboard if necessary
while (textFrame.width > artboardSize * 0.9 || textFrame.height > artboardSize * 0.9) {
fontSize -= 10;
textFrame.textRange.characterAttributes.size = fontSize;
textFrame.left = (artboardSize - textFrame.width) / 2;
textFrame.top = (artboardSize - textFrame.height) / 2;
}
}
// Rearrange artboards in a grid
var columns = Math.ceil(Math.sqrt(charSet.length));
var rows = Math.ceil(charSet.length / columns);
for (var i = 0; i < charSet.length; i++) {
var row = Math.floor(i / columns);
var col = i % columns;
var left = col * artboardSize;
var top = -row * artboardSize;
code
// Get the current artboard and its size
var currentArtboard = app.activeDocument.artboards[i];
var currentRect = currentArtboard.artboardRect;
var width = currentRect[2] - currentRect[0];
var height = currentRect[1] - currentRect[3];
// Move the current artboard to the desired position
currentArtboard.artboardRect = [left, top, left + width, top - height];
}
alert("Artboards rearranged successfully!");
Assistant
This Illustrator script creates individual artboards for each glyph in the specified character set and names them descriptively. Here is a breakdown of its functionality:
Character Set Definition: It begins by defining a character set, which includes uppercase and lowercase letters, numbers, and various punctuation marks.
Glyph Naming Function: The getGlyphName function returns descriptive names for each glyph using a mapping. If a glyph is not explicitly mapped, it defaults to the Unicode value of the glyph.
Document and Artboard Setup: It creates a new Illustrator document and specifies the size for each artboard.
Font Handling: It attempts to apply a preferred font from a predefined list. If none of the preferred fonts are available, it defaults to the first available font.
Artboard and Text Creation:
For each character in the character set, it creates a new artboard and assigns the glyph's descriptive name to the artboard.
A text frame is created with the glyph's character, and its font is set to the selected font at a specified size.
The script centers the text within the artboard and adjusts the font size if the text is too large to fit comfortably within the artboard.
Artboard Arrangement: The script calculates the number of rows and columns required to arrange the artboards, then positions them in a grid layout to maximize workspace efficiency.
Completion Alert: Finally, after rearranging the artboards, it shows an alert indicating the successful completion of the process.
To run this script, follow these steps:
Open Adobe Illustrator.
Go to File > Scripts > Other Script....
Select and run the script file containing the above code.
Ensure any necessary permissions are granted, and Illustrator is configured to allow custom scripts to execute. If you face issues with unavailable fonts or other errors, double-check the font names and adjust the character set or font handling logic accordingly.
User
Can you please check for errors and fix it for me?
Assistant
Certainly! Let's go through the script to identify any issues and correct them:
Quotation Marks for Glyphs: In your glyphNames object, single quotation marks were causing syntax errors because of incorrect use with characters ' and ’. These need to be corrected.
Artboard Addition: There's a redundant line when creating a new artboard. We need to specify dimensions upon creation.
Font Handling: Accessing the fonts via app.textFontInfo.get is likely incorrect as the method does not exist. Instead, you can directly loop through app.textFonts.
Document Translation: The artboard positioning seems incorrect ('left' and 'top' are switched).
Here is a corrected version of the script:
javascript
User
There is an error on this line : var currentArtboard = doc.artboards.add(artboardRect);
Assistant
I apologize for the oversight. The Artboards.add() method does not accept arguments to define its size in Adobe Illustrator scripting. Instead, you must create an artboard first and then resize it. Let's correct the script to handle this properly:
javascript
User
Error on this line : var currentArtboard = doc.artboards.add();
Assistant
I apologize for the inconvenience. Let's ensure that we handle this correctly for Adobe Illustrator scripting. In Illustrator scripting, when we add a new artboard with the artboards.add() method, it should work; however, we generally need to manage the artboard dimensions strictly through the artboardRect property after creation. Here's the revised part focusing on that:
javascript
// Illustrator Script: Create Glyph Artboards with Descriptive Names
// Character set definition is unchanged...
// Function to get a descriptive name for the glyph (unchanged)
// Document setup
var doc = app.documents.add();
var artboardSize = 1024;
// Font settings definition...
function findAvailableFont(preferredFonts) {
// Implementation to find suitable font (unchanged)
}
var preferredFonts = ["Arial", "Helvetica", "Myriad Pro", "Tahoma", "Verdana"];
var selectedFont = findAvailableFont(preferredFonts);
// Create artboards and text for each character
for (var i = 0; i < charSet.length; i++) {
var glyph = charSet[i];
var glyphName = getGlyphName(glyph);
// Add default-sized artboard; resize using the artboardRect
var currentArtboard = doc.artboards.add();
currentArtboard.name = glyphName;
// Resize the artboard to the desired dimensions
var artboardRect = [0, artboardSize, artboardSize, 0];
currentArtboard.artboardRect = artboardRect;
// Create text frame
var textFrame = doc.textFrames.add();
textFrame.contents = glyph;
textFrame.textRange.characterAttributes.textFont = selectedFont;
textFrame.textRange.characterAttributes.size = fontSize;
// Center the text on the artboard
textFrame.left = (artboardSize - textFrame.width) / 2;
textFrame.top = artboardSize - (artboardSize - textFrame.height) / 2; // Adjusted top alignment
// Adjust font size to fit artboard if necessary
while (textFrame.width > artboardSize * 0.9 || textFrame.height > artboardSize * 0.9) {
fontSize -= 10;
textFrame.textRange.characterAttributes.size = fontSize;
textFrame.left = (artboardSize - textFrame.width) / 2;
textFrame.top = artboardSize - (artboardSize - textFrame.height) / 2; // Adjusted top alignment
}
}
// Rearrange artboards in a grid (unchanged)
var columns = Math.ceil(Math.sqrt(charSet.length));
var rows = Math.ceil(charSet.length / columns);
for (var i = 0; i < charSet.length; i++) {
var row = Math.floor(i / columns);
var col = i % columns;
var left = col * artboardSize;
var top = -row * artboardSize;
// Get the current artboard and its size
var currentArtboard = doc.artboards[i];
var width = artboardSize; // Since it's set as a fixed size
var height = artboardSize;
// Position the artboard in the grid
currentArtboard.artboardRect = [left, top, left + width, top - height];
}
alert("Artboards rearranged successfully!");
User
There is an error on this line : var currentArtboard = doc.artboards.add();
Assistant
Let's address the error in your script. It seems there is a misunderstanding regarding how the artboards.add() method should be used. While doc.artboards.add() should typically work, issues may arise due to various internal restrictions or configurations within Illustrator's scripting environment.
To address this, let's ensure the script implements the artboard addition correctly by adjusting the size after creation. If it's still producing errors, we might try double-checking Illustrator settings or the script's environment. Here's a streamlined version of how to handle this:
Certainly! Let's create a script for Adobe Illustrator that will iterate through a set of glyphs, create artboards for each glyph, and name the artboards according to the descriptions in the glyphNames object. Each artboard will be 1024x1024 pixels in size.
Here's how you can do it:
javascript
User
Error on this line : var currentArtboard = doc.artboards.add([0, -artboardSize, artboardSize, 0]);
Assistant
I apologize for the oversight. It looks like the syntax used for adding an artboard isn't working as expected in your case. In Adobe Illustrator scripting, the add() method for an Artboards collection is a bit particular about parameters when it doesn't directly take an argument for dimensions and positions of an artboard.
Instead, we should set the size using the artboardRect immediately after creation. Here's an adjusted script that should address the issue:
javascript
User
error on line 43
Assistant
Let's address the issue occurring on line 43, which corresponds to setting the artboardRect for the current artboard. It's essential to ensure that when setting the artboardRect, the values are consistently ordered and correctly calculated for Illustrator scripting. Here's a corrected script that should work:
javascript
User
Fix error on line 42:
// Character set
var charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"abcdefghijklmnopqrstuvwxyz" +
"1234567890" +
". , ; : "„'’‚‹›»«*{}/-–_<>?!$@&+^#";
// Document setup
var doc = app.documents.add();
var artboardSize = 1024;
var padding = 50; // Space between artboards
var columns = 10; // Number of artboards per row
// Function to add artboards
function addArtboard(left, top, right, bottom, glyphName) {
// Add a new artboard if it's not the first one
var newArtboard = doc.artboards.add();
newArtboard.artboardRect = [left, top, right, bottom];
newArtboard.name = glyphName;
}
// Create artboards and assign names in a grid layout
for (var i = 0; i < charSet.length; i++) {
var glyph = charSet[i];
var glyphName = glyphNames[glyph] || 'Glyph_' + glyph.charCodeAt(0);
code
Assistant
The issue might be arising due to how the artboard rectangles are being set and managed, especially during the creation of the first artboard. Let's go through how we can better manage artboard creation and size modifications.
Here's an updated version of your script with a focus on handling the first artboard separately and managing artboard rectangles more consistently:
javascript
Not yet included in a published release.
// Corrected Illustrator Script: Create Glyph Artboards with Descriptive Names
// Character set
var charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"abcdefghijklmnopqrstuvwxyz" +
"1234567890" +
". , ; : \"„'’‚…‹›»«*[](){}/-–_<>?!$@&+^#";
// Function to get a descriptive name for the glyph
function getGlyphName(glyph) {
var glyphNames = {
'A': 'Uppercase_A', 'B': 'Uppercase_B', 'C': 'Uppercase_C', 'D': 'Uppercase_D', 'E': 'Uppercase_E',
'F': 'Uppercase_F', 'G': 'Uppercase_G', 'H': 'Uppercase_H', 'I': 'Uppercase_I', 'J': 'Uppercase_J',
'K': 'Uppercase_K', 'L': 'Uppercase_L', 'M': 'Uppercase_M', 'N': 'Uppercase_N', 'O': 'Uppercase_O',
'P': 'Uppercase_P', 'Q': 'Uppercase_Q', 'R': 'Uppercase_R', 'S': 'Uppercase_S', 'T': 'Uppercase_T',
'U': 'Uppercase_U', 'V': 'Uppercase_V', 'W': 'Uppercase_W', 'X': 'Uppercase_X', 'Y': 'Uppercase_Y',
'Z': 'Uppercase_Z', 'a': 'Lowercase_a', 'b': 'Lowercase_b', 'c': 'Lowercase_c', 'd': 'Lowercase_d',
'e': 'Lowercase_e', 'f': 'Lowercase_f', 'g': 'Lowercase_g', 'h': 'Lowercase_h', 'i': 'Lowercase_i',
'j': 'Lowercase_j', 'k': 'Lowercase_k', 'l': 'Lowercase_l', 'm': 'Lowercase_m', 'n': 'Lowercase_n',
'o': 'Lowercase_o', 'p': 'Lowercase_p', 'q': 'Lowercase_q', 'r': 'Lowercase_r', 's': 'Lowercase_s',
't': 'Lowercase_t', 'u': 'Lowercase_u', 'v': 'Lowercase_v', 'w': 'Lowercase_w', 'x': 'Lowercase_x',
'y': 'Lowercase_y', 'z': 'Lowercase_z', '0': 'Number_0', '1': 'Number_1', '2': 'Number_2',
'3': 'Number_3', '4': 'Number_4', '5': 'Number_5', '6': 'Number_6', '7': 'Number_7', '8': 'Number_8',
'9': 'Number_9', '.': 'Period', ',': 'Comma', ';': 'Semicolon', ':': 'Colon', '"': 'Double_Quote',
'„': 'Double_Low_9_Quotation_Mark', '\'': 'Single_Quotation_Mark', // Corrected quotation marks
'’': 'Right_Single_Quotation_Mark', '‚': 'Single_Low_9_Quotation_Mark', '…': 'Ellipsis',
'‹': 'Single_Left_Pointing_Angle_Quotation_Mark', '›': 'Single_Right_Pointing_Angle_Quotation_Mark',
'»': 'Right_Pointing_Double_Angle_Quotation_Mark', '«': 'Left_Pointing_Double_Angle_Quotation_Mark',
'*': 'Asterisk', '[': 'Left_Square_Bracket', ']': 'Right_Square_Bracket', '(': 'Left_Parenthesis',
')': 'Right_Parenthesis', '{': 'Left_Curly_Bracket', '}': 'Right_Curly_Bracket', '/': 'Forward_Slash',
'–': 'En_Dash', '-': 'Hyphen', '_': 'Underscore', '<': 'Less_Than', '>': 'Greater_Than',
'?': 'Question_Mark', '!': 'Exclamation_Mark', '$': 'Dollar_Sign', '@': 'At_Sign', '&': 'Ampersand',
'+': 'Plus_Sign', '^': 'Caret', '#': 'Hash'
};
return glyphNames[glyph] || 'Glyph_' + glyph.charCodeAt(0);
}
// Document setup
var doc = app.documents.add();
var artboardSize = 1024;
// Font settings
var fontSize = 800; // Starting font size, will be adjusted to fit
function findAvailableFont(preferredFonts) {
for (var i = 0; i < app.textFonts.length; i++) {
for (var j = 0; j < preferredFonts.length; j++) {
if (app.textFonts[i].name == preferredFonts[j]) {
return app.textFonts[i];
}
}
}
// If no preferred fonts are found, return the first available font
return app.textFonts[0];
}
// List of preferred fonts (in order of preference)
var preferredFonts = ["Arial", "Helvetica", "Myriad Pro", "Tahoma", "Verdana"];
var selectedFont = findAvailableFont(preferredFonts);
// Create artboards and text for each character
for (var i = 0; i < charSet.length; i++) {
var glyph = charSet[i];
var glyphName = getGlyphName(glyph);
// Create new artboard
var artboardRect = [0, 0, artboardSize, artboardSize];
var currentArtboard = doc.artboards.add(artboardRect);
currentArtboard.name = glyphName;
// Create text frame
var textFrame = doc.textFrames.add();
textFrame.contents = glyph;
textFrame.textRange.characterAttributes.textFont = selectedFont;
textFrame.textRange.characterAttributes.size = fontSize;
// Center text
textFrame.left = (artboardSize - textFrame.width) / 2;
textFrame.top = artboardSize - (artboardSize - textFrame.height) / 2; // Corrected top alignment
// Adjust font size to fit artboard if necessary
while (textFrame.width > artboardSize * 0.9 || textFrame.height > artboardSize * 0.9) {
fontSize -= 10;
textFrame.textRange.characterAttributes.size = fontSize;
textFrame.left = (artboardSize - textFrame.width) / 2;
textFrame.top = artboardSize - (artboardSize - textFrame.height) / 2; // Corrected top alignment
}
}
// Rearrange artboards in a grid
var columns = Math.ceil(Math.sqrt(charSet.length));
var rows = Math.ceil(charSet.length / columns);
for (var i = 0; i < charSet.length; i++) {
var row = Math.floor(i / columns);
var col = i % columns;
var left = col * artboardSize;
var top = -row * artboardSize;
// Get the current artboard and its size
var currentArtboard = doc.artboards[i];
var currentRect = currentArtboard.artboardRect;
var width = currentRect[2] - currentRect[0];
var height = currentRect[1] - currentRect[3];
// Move the current artboard to the desired position
currentArtboard.artboardRect = [left, top, left + width, top - height];
}
alert("Artboards rearranged successfully!");
Key Fixes:
Quoting Glyphs Properly: Adjusted the characters for correct use of single quotes ' and corrected some character mappings.
Removed Redundant Artboard Addition: Removed the redundant app.activeDocument.artboards.add() line.
Corrected Font Handling: Used a direct loop over app.textFonts to check for available fonts.
Text Frame Positioning: Adjusted the calculation for centering text vertically; note the correction on textFrame.top.
This should correct the errors in the initial script and allow it to run successfully in Adobe Illustrator. Make sure to test it within Illustrator's script interface.
// Illustrator Script: Create Glyph Artboards with Descriptive Names
// Character set
var charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"abcdefghijklmnopqrstuvwxyz" +
"1234567890" +
". , ; : \"„'’‚…‹›»«*[](){}/-–_<>?!$@&+^#";
// Function to get a descriptive name for the glyph
function getGlyphName(glyph) {
var glyphNames = {
'A': 'Uppercase_A', 'B': 'Uppercase_B', 'C': 'Uppercase_C', 'D': 'Uppercase_D', 'E': 'Uppercase_E',
'F': 'Uppercase_F', 'G': 'Uppercase_G', 'H': 'Uppercase_H', 'I': 'Uppercase_I', 'J': 'Uppercase_J',
'K': 'Uppercase_K', 'L': 'Uppercase_L', 'M': 'Uppercase_M', 'N': 'Uppercase_N', 'O': 'Uppercase_O',
'P': 'Uppercase_P', 'Q': 'Uppercase_Q', 'R': 'Uppercase_R', 'S': 'Uppercase_S', 'T': 'Uppercase_T',
'U': 'Uppercase_U', 'V': 'Uppercase_V', 'W': 'Uppercase_W', 'X': 'Uppercase_X', 'Y': 'Uppercase_Y',
'Z': 'Uppercase_Z', 'a': 'Lowercase_a', 'b': 'Lowercase_b', 'c': 'Lowercase_c', 'd': 'Lowercase_d',
'e': 'Lowercase_e', 'f': 'Lowercase_f', 'g': 'Lowercase_g', 'h': 'Lowercase_h', 'i': 'Lowercase_i',
'j': 'Lowercase_j', 'k': 'Lowercase_k', 'l': 'Lowercase_l', 'm': 'Lowercase_m', 'n': 'Lowercase_n',
'o': 'Lowercase_o', 'p': 'Lowercase_p', 'q': 'Lowercase_q', 'r': 'Lowercase_r', 's': 'Lowercase_s',
't': 'Lowercase_t', 'u': 'Lowercase_u', 'v': 'Lowercase_v', 'w': 'Lowercase_w', 'x': 'Lowercase_x',
'y': 'Lowercase_y', 'z': 'Lowercase_z', '0': 'Number_0', '1': 'Number_1', '2': 'Number_2',
'3': 'Number_3', '4': 'Number_4', '5': 'Number_5', '6': 'Number_6', '7': 'Number_7', '8': 'Number_8',
'9': 'Number_9', '.': 'Period', ',': 'Comma', ';': 'Semicolon', ':': 'Colon', '"': 'Double_Quote',
'„': 'Double_Low_9_Quotation_Mark', '\'': 'Single_Quotation_Mark', // Corrected quotation marks
'’': 'Right_Single_Quotation_Mark', '‚': 'Single_Low_9_Quotation_Mark', '…': 'Ellipsis',
'‹': 'Single_Left_Pointing_Angle_Quotation_Mark', '›': 'Single_Right_Pointing_Angle_Quotation_Mark',
'»': 'Right_Pointing_Double_Angle_Quotation_Mark', '«': 'Left_Pointing_Double_Angle_Quotation_Mark',
'*': 'Asterisk', '[': 'Left_Square_Bracket', ']': 'Right_Square_Bracket', '(': 'Left_Parenthesis',
')': 'Right_Parenthesis', '{': 'Left_Curly_Bracket', '}': 'Right_Curly_Bracket', '/': 'Forward_Slash',
'–': 'En_Dash', '-': 'Hyphen', '_': 'Underscore', '<': 'Less_Than', '>': 'Greater_Than',
'?': 'Question_Mark', '!': 'Exclamation_Mark', '$': 'Dollar_Sign', '@': 'At_Sign', '&': 'Ampersand',
'+': 'Plus_Sign', '^': 'Caret', '#': 'Hash'
};
return glyphNames[glyph] || 'Glyph_' + glyph.charCodeAt(0);
}
// Document setup
var doc = app.documents.add();
var artboardSize = 1024;
// Font settings
var fontSize = 800; // Starting font size, will be adjusted to fit
function findAvailableFont(preferredFonts) {
for (var i = 0; i < app.textFonts.length; i++) {
for (var j = 0; j < preferredFonts.length; j++) {
if (app.textFonts[i].name == preferredFonts[j]) {
return app.textFonts[i];
}
}
}
// If no preferred fonts are found, return the first available font
return app.textFonts[0];
}
// List of preferred fonts (in order of preference)
var preferredFonts = ["Arial", "Helvetica", "Myriad Pro", "Tahoma", "Verdana"];
var selectedFont = findAvailableFont(preferredFonts);
// Create artboards and text for each character
for (var i = 0; i < charSet.length; i++) {
var glyph = charSet[i];
var glyphName = getGlyphName(glyph);
// Add a default artboard
var currentArtboard = doc.artboards.add();
currentArtboard.name = glyphName;
var artboardRect = [0, 0, artboardSize, -artboardSize];
currentArtboard.artboardRect = artboardRect; // Resize after creation
// Create text frame
var textFrame = doc.textFrames.add();
textFrame.contents = glyph;
textFrame.textRange.characterAttributes.textFont = selectedFont;
textFrame.textRange.characterAttributes.size = fontSize;
// Center text
textFrame.left = (artboardSize - textFrame.width) / 2;
textFrame.top = artboardSize - (artboardSize - textFrame.height) / 2; // Corrected top alignment
// Adjust font size to fit artboard if necessary
while (textFrame.width > artboardSize * 0.9 || textFrame.height > artboardSize * 0.9) {
fontSize -= 10;
textFrame.textRange.characterAttributes.size = fontSize;
textFrame.left = (artboardSize - textFrame.width) / 2;
textFrame.top = artboardSize - (artboardSize - textFrame.height) / 2; // Corrected top alignment
}
}
// Rearrange artboards in a grid
var columns = Math.ceil(Math.sqrt(charSet.length));
var rows = Math.ceil(charSet.length / columns);
for (var i = 0; i < charSet.length; i++) {
var row = Math.floor(i / columns);
var col = i % columns;
var left = col * artboardSize;
var top = -row * artboardSize;
// Get the current artboard and its size
var currentArtboard = doc.artboards[i];
var currentRect = currentArtboard.artboardRect;
var width = currentRect[2] - currentRect[0];
var height = currentRect[1] - currentRect[3];
// Move the current artboard to the desired position
currentArtboard.artboardRect = [left, top, left + width, top - height];
}
alert("Artboards rearranged successfully!");
Key Adjustments:
Artboard Creation and Resizing: Removed parameters from doc.artboards.add() method. Instead, added an artboard using the basic method and then specified its size using currentArtboard.artboardRect.
Text Alignment: Corrected the vertical centering of the text object on each artboard.
This should resolve the original error and run successfully, creating artboards as intended. Make sure you are executing this script in Illustrator's script execution environment.
Key Changes:
Artboard Rect Management: The artboard is created with add(), then resized using .artboardRect immediately after to ensure correct dimensions.
Top Alignment: The text's placement on the artboard ensures proper mathematical correction for centering.
This version focuses on resolving the issues you encountered while ensuring all aspects are correctly handled in the Adobe Illustrator script. Test this script within Illustrator's scripting environment, and it should create individual artboards for each glyph efficiently.
// Character set
var charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"abcdefghijklmnopqrstuvwxyz" +
"1234567890" +
". , ; : \"„'’‚…‹›»«*[](){}/-–_<>?!$@&+^#";
// Function to get descriptive name for a glyph
function getGlyphName(glyph) {
var glyphNames = {
// Define names for characters...
// For brevity, I'm skipping the long map here, assuming it's in place
'A': 'Uppercase_A', 'B': 'Uppercase_B',
// ...
'&': 'Ampersand', '+': 'Plus_Sign', '^': 'Caret', '#': 'Hash'
};
return glyphNames[glyph] || 'Glyph_' + glyph.charCodeAt(0);
}
// Document setup
var doc = app.documents.add();
var artboardSize = 1024;
// Font settings
var fontSize = 800; // Starting font size, will be adjusted to fit
function findAvailableFont(preferredFonts) {
for (var i = 0; i < app.textFonts.length; i++) {
if (preferredFonts.indexOf(app.textFonts[i].name) !== -1) {
return app.textFonts[i];
}
}
return app.textFonts[0];
}
// List of preferred fonts
var preferredFonts = ["Arial", "Helvetica", "Myriad Pro", "Tahoma", "Verdana"];
var selectedFont = findAvailableFont(preferredFonts);
// Create artboards and text for each character
for (var i = 0; i < charSet.length; i++) {
var glyph = charSet[i];
var glyphName = getGlyphName(glyph);
// Add artboard with default size
var currentArtboard = doc.artboards.add([0, 0, 100, -100]);
currentArtboard.name = glyphName;
// Correct the size of the artboard to desired dimensions
var artboardRect = [0, artboardSize, artboardSize, 0];
doc.artboards.setActiveArtboardIndex(i);
currentArtboard.artboardRect = artboardRect; // Resize after creation
// Create text frame
var textFrame = doc.textFrames.add();
textFrame.contents = glyph;
textFrame.textRange.characterAttributes.textFont = selectedFont;
textFrame.textRange.characterAttributes.size = fontSize;
// Center text
textFrame.position = [
(artboardSize - textFrame.width) / 2,
artboardSize - (artboardSize - textFrame.height) / 2
];
// Adjust font size to fit artboard if necessary
while (textFrame.width > artboardSize * 0.9 || textFrame.height > artboardSize * 0.9) {
fontSize -= 10;
textFrame.textRange.characterAttributes.size = fontSize;
textFrame.position = [
(artboardSize - textFrame.width) / 2,
artboardSize - (artboardSize - textFrame.height) / 2
];
}
}
// Rearrange artboards in a grid
var columns = Math.ceil(Math.sqrt(charSet.length));
for (var i = 0; i < charSet.length; i++) {
var row = Math.floor(i / columns);
var col = i % columns;
var left = col * artboardSize;
var top = -row * artboardSize;
var currentArtboard = doc.artboards[i];
currentArtboard.artboardRect = [left, top, left + artboardSize, top - artboardSize];
}
alert("Artboards rearranged successfully!");
Key Points:
Artboard Addition: A temporary initial size is set when the artboard is added, then immediately resized to the desired dimensions.
Text Frame Centering: Calculations ensure the text is centered correctly within each artboard.
Please ensure that Illustrator is configured correctly to run scripts and there are no permission constraints causing issues. If errors persist, try running a simple test script to create an artboard separately to isolate the problem.
Let me know how this approach works for you or if further adjustments are required!
Character Set & Glyph Names: A character set is defined, and a dictionary (glyphNames) provides descriptive names for each glyph.
Document Setup: A new Illustrator document is created.
Artboard Creation: For each character in the set, an artboard is created with dimensions [0, -size, size, 0] to ensure a 1024x1024 size. The artboard is then named using the glyph's descriptive name.
Error Handling: If a glyph is not found in the glyphNames object, it defaults to using the glyph's Unicode value.
This script should execute within Adobe Illustrator's scripting environment to create separate artboards for each glyph as specified, naming them according to the given mappings.
Artboard Creation: First, add a new artboard with doc.artboards.add(). Then, retrieve the newly added artboard using doc.artboards[doc.artboards.length - 1].
Artboard Rect Assignment: After obtaining the reference to the artboard, adjust its size using artboardRect.
Naming: Set the name once the artboard size has been adjusted.
This should correctly create and size each artboard, associating them with the appropriate names. Run this script in Illustrator's scripting environment for it to take effect. Let me know if you encounter additional issues or require further changes!
Artboard Rectangle: When setting the artboardRect, use an array [left, top, right, bottom] with top greater than bottom for the document's coordinate system. The y-values should be negative because Illustrator uses a coordinate system where the origin is at the top-left of the document.
Add & Resize Artboard: The add() method creates a default new artboard, after which you access it using doc.artboards[doc.artboards.length - 1] and set its dimensions using artboardRect.
This script should handle creating and naming the artboards without the issues you've been encountering. Let me know how it works for you!
// Calculate the row and column for grid arrangement
var row = Math.floor(i / columns);
var column = i % columns;
// Calculate the position for the new artboard
var left = column * (artboardSize + padding);
var top = -row * (artboardSize + padding);
var right = left + artboardSize;
var bottom = top - artboardSize;
// Handle the first artboard differently
if (i === 0) {
// Modify the first artboard's rectangle directly
doc.artboards[0].artboardRect = [left, top, right, bottom];
doc.artboards[0].name = glyphName;
} else {
// Add new artboard for the rest
addArtboard(left, top, right, bottom, glyphName);
}
}
alert("Artboards created and arranged in a grid!");
// Character set
var charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"abcdefghijklmnopqrstuvwxyz" +
"1234567890" +
". , ; : \"„'’‚‹›»«*[](){}/-–_<>?!$@&+^#";
// Descriptive glyph names
var glyphNames = {
'A': 'Uppercase_A', 'B': 'Uppercase_B', 'C': 'Uppercase_C', 'D': 'Uppercase_D', 'E': 'Uppercase_E',
'F': 'Uppercase_F', 'G': 'Uppercase_G', 'H': 'Uppercase_H', 'I': 'Uppercase_I', 'J': 'Uppercase_J',
'K': 'Uppercase_K', 'L': 'Uppercase_L', 'M': 'Uppercase_M', 'N': 'Uppercase_N', 'O': 'Uppercase_O',
'P': 'Uppercase_P', 'Q': 'Uppercase_Q', 'R': 'Uppercase_R', 'S': 'Uppercase_S', 'T': 'Uppercase_T',
'U': 'Uppercase_U', 'V': 'Uppercase_V', 'W': 'Uppercase_W', 'X': 'Uppercase_X', 'Y': 'Uppercase_Y',
'Z': 'Uppercase_Z', 'a': 'Lowercase_a', 'b': 'Lowercase_b', 'c': 'Lowercase_c', 'd': 'Lowercase_d',
'e': 'Lowercase_e', 'f': 'Lowercase_f', 'g': 'Lowercase_g', 'h': 'Lowercase_h', 'i': 'Lowercase_i',
'j': 'Lowercase_j', 'k': 'Lowercase_k', 'l': 'Lowercase_l', 'm': 'Lowercase_m', 'n': 'Lowercase_n',
'o': 'Lowercase_o', 'p': 'Lowercase_p', 'q': 'Lowercase_q', 'r': 'Lowercase_r', 's': 'Lowercase_s',
't': 'Lowercase_t', 'u': 'Lowercase_u', 'v': 'Lowercase_v', 'w': 'Lowercase_w', 'x': 'Lowercase_x',
'y': 'Lowercase_y', 'z': 'Lowercase_z', '0': 'Number_0', '1': 'Number_1', '2': 'Number_2',
'3': 'Number_3', '4': 'Number_4', '5': 'Number_5', '6': 'Number_6', '7': 'Number_7', '8': 'Number_8',
'9': 'Number_9', '.': 'Period', ',': 'Comma', ';': 'Semicolon', ':': 'Colon', '"': 'Double_Quote',
'„': 'Double_Low_9_Quotation_Mark', '\'': 'Left_Single_Quotation_Mark',
'’': 'Right_Single_Quotation_Mark', '‚': 'Single_Low_9_Quotation_Mark', '‹': 'Single_Left_Pointing_Angle_Quotation_Mark',
'›': 'Single_Right_Pointing_Angle_Quotation_Mark', '»': 'Right_Pointing_Double_Angle_Quotation_Mark',
'«': 'Left_Pointing_Double_Angle_Quotation_Mark', '*': 'Asterisk', '[': 'Left_Square_Bracket',
']': 'Right_Square_Bracket', '(': 'Left_Parenthesis', ')': 'Right_Parenthesis',
'{': 'Left_Curly_Bracket', '}': 'Right_Curly_Bracket', '/': 'Forward_Slash',
'–': 'En_Dash', '-': 'Hyphen', '_': 'Underscore', '<': 'Less_Than', '>': 'Greater_Than',
'?': 'Question_Mark', '!': 'Exclamation_Mark', '$': 'Dollar_Sign', '@': 'At_Sign',
'&': 'Ampersand', '+': 'Plus_Sign', '^': 'Caret', '#': 'Hash'
};
// Document setup
var doc = app.documents.add();
var artboardSize = 1024;
var padding = 50; // Space between artboards
var columns = 10; // Number of artboards per row
// Function to add artboards
function addArtboard(left, top, right, bottom, glyphName) {
var newArtboard = doc.artboards.add();
newArtboard.artboardRect = [left, top, right, bottom];
newArtboard.name = glyphName;
}
// Create artboards and assign names in a grid layout
for (var i = 0; i < charSet.length; i++) {
var glyph = charSet[i];
var glyphName = glyphNames[glyph] || 'Glyph_' + glyph.charCodeAt(0);
// Calculate the row and column for grid arrangement
var row = Math.floor(i / columns);
var column = i % columns;
// Calculate the position for the new artboard
var left = column * (artboardSize + padding);
var top = -row * (artboardSize + padding);
var right = left + artboardSize;
var bottom = top - artboardSize;
// Handle the first artboard differently
if (i === 0) {
// Modify the first artboard's rectangle directly
var firstArtboard = doc.artboards[0];
firstArtboard.artboardRect = [left, top, right, bottom];
firstArtboard.name = glyphName;
} else {
// Add new artboard for the rest
addArtboard(left, top, right, bottom, glyphName);
}
}
alert("Artboards created and arranged in a grid!");
Key Points:
Managing the First Artboard: The script modifies the rectangle of the first artboard directly if i === 0. This is crucial because Adobe Illustrator creates a default artboard with every new document, and adjusting its size prevents overlap or redundant additions.
Adding New Artboards: For subsequent glyphs, new artboards are added through a function that both creates and positions them based on the current row and column.
This approach handles artboard positioning and updating effectively within the constraints of Adobe Illustrator's scripting capabilities. Let me know if this resolves your issue!