Skip to content

Commit

Permalink
Updated RenameArtboardAsSize.jsx
Browse files Browse the repository at this point in the history
Added user interface with options
  • Loading branch information
creold committed Jan 5, 2024
1 parent 3d5eee1 commit 977c9d3
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 40 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
## Hi
This is a collection of JS scripts for Adobe Illustrator. All scripts created by me, sometimes using parts of other authors’ code. The [Github Gist](https://gist.github.com/creold) contains the small scripts that are not included in the main collection.

The descriptions for each file can be found in the file’s header text. Test environment: Illustrator CS6, CC 2022, 2023 (Windows), CC 2018-2023 (Mac OS).
The descriptions for each file can be found in the file’s header text. Test environment: Illustrator CS6, CC 2019-2024 (Windows), CC 2019-2024 (Mac OS).

## How to download one script
1. In the script description, click the "Direct Link" button.
Expand Down Expand Up @@ -92,7 +92,7 @@ Click the category name to learn more about the scripts in the selected category
* [FitArtboardsToArtwork](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.md#fitartboardstoartwork) `upd, 18.09.2023`
* [MoveArtboards](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.md#moveartboards) `upd, 04.05.2023`
* [RenameArtboardAsLayer](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.md#renameartboardaslayer) `upd, 14.09.2022`
* [RenameArtboardAsSize](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.md#renameartboardassize) `upd, 22.12.2022`
* [RenameArtboardAsSize](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.md#renameartboardassize) `upd, 05.01.2024`
* [RenameArtboardAsTopObj](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.md#renameartboardastopobj) `upd, 14.09.2022`

### [Color](md/Color.md)
Expand Down
4 changes: 2 additions & 2 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
## 👨‍💻 Привет
Это коллекция авторских скриптов для Adobe Illustrator. Небольшие скрипты, не вошедшие в основную коллекцию, выкладываю на [Github Gist](https://gist.github.com/creold).

Описание каждого скрипта также находится внутри его файла. Тестировалось в Illustrator CS6, CC 2022, 2023 (Windows), CC 2018-2023 (Mac OS).
Описание каждого скрипта также находится внутри его файла. Тестировалось в Illustrator CS6, CC 2019-2024 (Windows), CC 2019-2024 (Mac OS).

## Как скачать один скрипт
1. В описании скрипта нажмите кнопку «Прямая ссылка».
Expand Down Expand Up @@ -93,7 +93,7 @@
* [FitArtboardsToArtwork](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.ru.md#fitartboardstoartwork) `upd, 18.09.2023`
* [MoveArtboards](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.ru.md#moveartboards) `upd, 04.05.2023`
* [RenameArtboardAsLayer](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.ru.md#renameartboardaslayer) `upd, 14.09.2022`
* [RenameArtboardAsSize](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.ru.md#renameartboardassize) `upd, 22.12.2022`
* [RenameArtboardAsSize](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.ru.md#renameartboardassize) `upd, 05.01.2024`
* [RenameArtboardAsTopObj](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.ru.md#renameartboardastopobj) `upd, 14.09.2022`

### [Color](md/Color.ru.md)
Expand Down
3 changes: 2 additions & 1 deletion jsx/RenameArtboardAsLayer.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
RenameArtboardAsLayer.jsx for Adobe Illustrator
Description: The script renames each Artboard by the custom name of Layer with the first visible unlocked item on it.
Date: September, 2022
Date: October, 2019
Modification date: September, 2022
Author: Sergey Osokin, email: hi@sergosokin.ru
Installation: https://github.com/creold/illustrator-scripts#how-to-run-scripts
Expand Down
124 changes: 96 additions & 28 deletions jsx/RenameArtboardAsSize.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
RenameArtboardAsSize.jsx for Adobe Illustrator
Description: The script fills in the name of artboard its size
Date: December, 2022
Description: The script Renames artboards according to their size in document units
Date: September, 2018
Modification date: January, 2024
Author: Sergey Osokin, email: hi@sergosokin.ru
Installation: https://github.com/creold/illustrator-scripts#how-to-run-scripts
Expand All @@ -11,6 +12,7 @@
0.2 Added more units (yards, meters, etc.) support if the document is saved
0.2.1 Added size correction in large canvas mode
0.2.2 Added new units API for CC 2023 v27.1.1
0.3 Added user interface
Donate (optional):
If you find this script helpful, you can buy me a coffee
Expand All @@ -20,10 +22,10 @@
- via YooMoney https://yoomoney.ru/to/410011149615582
NOTICE:
Tested with Adobe Illustrator CC 2018-2023 (Mac), 2023 (Win).
Tested with Adobe Illustrator CC 2019-2024 (Mac/Win).
This script is provided "as is" without warranty of any kind.
Free to use, not for sale
Released under the MIT license
http://opensource.org/licenses/mit-license.php
Expand All @@ -37,7 +39,7 @@ function main() {
var CFG = {
units: getUnits(), // Active document units
isSaveName: true, // Set false to overwrite the full name
isRound: false, // Set true to get a round number
isRound: true, // Set true to get a round number
precision: 2, // Size rounding precision
isAddUnit: true,
separator: '_'
Expand All @@ -48,37 +50,72 @@ function main() {
return;
}

var doc = activeDocument,
width, height,
size = '';
var doc = activeDocument;
var idx = doc.artboards.getActiveArtboardIndex();

// Scale factor for Large Canvas mode
CFG.sf = doc.scaleFactor ? doc.scaleFactor : 1;

for (var i = 0, len = doc.artboards.length; i < len; i++) {
var currAb = doc.artboards[i];

width = CFG.sf * convertUnits(currAb.artboardRect[2] - currAb.artboardRect[0], 'px', CFG.units);
height = CFG.sf * convertUnits(currAb.artboardRect[1] - currAb.artboardRect[3], 'px', CFG.units);

if (CFG.isRound) {
width = Math.round(width);
height = Math.round(height);
} else {
width = width.toFixed(CFG.precision);
height = height.toFixed(CFG.precision);
}
// INTERFACE
var win = new Window('dialog', 'Rename Artboard As Size');
win.alignChildren = ['fill', 'fill'];

size = width + 'x' + height;
if (CFG.isAddUnit) size += CFG.units;
// Range
var rangePnl = win.add('panel', undefined, 'Artboards range');
rangePnl.alignChildren = ['fill', 'center'];
rangePnl.margins = [10, 15, 10, 8];

if (CFG.isSaveName) {
currAb.name += CFG.separator + size;
} else {
currAb.name = size;
}
var isAll = rangePnl.add('radiobutton', undefined, 'All ' + doc.artboards.length + ' artboards');
isAll.value = true;

var isCurr = rangePnl.add('radiobutton', undefined, 'Active artboard #' + (idx + 1));

// Range
var optPnl = win.add('panel', undefined, 'Options');
optPnl.alignChildren = ['fill', 'center'];
optPnl.margins = [10, 15, 10, 8];

var isSaveName = optPnl.add('checkbox', undefined, 'Add size as suffix');
isSaveName.value = CFG.isSaveName;

var isRound = optPnl.add('checkbox', undefined, 'Round to integer');
isRound.value = CFG.isRound;

var isAddUnit = optPnl.add('checkbox', undefined, 'Add units after size');
isAddUnit.value = CFG.isAddUnit;

// Buttons
var btns = win.add('group');
btns.alignChildren = ['fill', 'center'];

var cancel = btns.add('button', undefined, 'Cancel', { name: 'cancel' });
cancel.helpTip = 'Press Esc to Close';

var ok = btns.add('button', undefined, 'OK', { name: 'ok' });
ok.helpTip = 'Press Enter to Run';

var copyright = win.add('statictext', undefined, '\u00A9 Sergey Osokin. Visit Github');
copyright.justify = 'center';

cancel.onClick = win.close;

ok.onClick = function () {
var range = isAll.value ? doc.artboards : [doc.artboards[idx]];
CFG.isSaveName = isSaveName.value;
CFG.isRound = isRound.value;
CFG.isAddUnit = isAddUnit.value;
for (var i = 0, len = range.length; i < len; i++) {
renameArtboard(range[i], CFG);
}
win.close();
}

copyright.addEventListener('mousedown', function () {
openURL('https://github.com/creold');
});

win.center();
win.show();
}

// Get active document ruler units
Expand Down Expand Up @@ -113,11 +150,42 @@ function getUnits() {
}
}

// Rename an artboard by its size
function renameArtboard(ab, prefs) {
var abName = ab.name;
var separator = /\s/.test(abName) ? ' ' : (/-/.test(abName) ? '-' : prefs.separator);

var width = prefs.sf * convertUnits(ab.artboardRect[2] - ab.artboardRect[0], 'px', prefs.units);
var height = prefs.sf * convertUnits(ab.artboardRect[1] - ab.artboardRect[3], 'px', prefs.units);

width = prefs.isRound ? Math.round(width) : width.toFixed(prefs.precision);
height = prefs.isRound ? Math.round(height) : height.toFixed(prefs.precision);

var size = width + 'x' + height;
if (prefs.isAddUnit) size += prefs.units;

if (prefs.isSaveName) {
ab.name += separator + size;
} else {
ab.name = size;
}
}

// Convert units of measurement
function convertUnits(value, currUnits, newUnits) {
return UnitValue(value, currUnits).as(newUnits);
}

// Open link in browser
function openURL(url) {
var html = new File(Folder.temp.absoluteURI + '/aisLink.html');
html.open('w');
var htmlBody = '<html><head><META HTTP-EQUIV=Refresh CONTENT="0; URL=' + url + '"></head><body> <p></body></html>';
html.write(htmlBody);
html.close();
html.execute();
}

try {
main();
} catch (e) {}
3 changes: 2 additions & 1 deletion jsx/RenameArtboardAsTopObj.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
RenameArtboardAsTopObj.jsx for Adobe Illustrator
Description: The script renames each Artboard by the custom name of the first visible unlocked item on it
Date: September, 2022
Date: September, 2018
Modification date: September, 2022
Author: Sergey Osokin, email: hi@sergosokin.ru
Installation: https://github.com/creold/illustrator-scripts#how-to-run-scripts
Expand Down
6 changes: 3 additions & 3 deletions md/Artboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* [FitArtboardsToArtwork](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.md#fitartboardstoartwork) `upd, 18.09.2023`
* [MoveArtboards](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.md#moveartboards) `upd, 04.05.2023`
* [RenameArtboardAsLayer](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.md#renameartboardaslayer) `upd, 14.09.2022`
* [RenameArtboardAsSize](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.md#renameartboardassize) `upd, 22.12.2022`
* [RenameArtboardAsSize](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.md#renameartboardassize) `upd, 05.01.2024`
* [RenameArtboardAsTopObj](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.md#renameartboardastopobj) `upd, 14.09.2022`

## ArtboardsFinder
Expand Down Expand Up @@ -95,9 +95,9 @@ The script renames each Artboard by the custom name of Layer with the first visi
## RenameArtboardAsSize
[![Direct](https://img.shields.io/badge/Direct%20Link-RenameArtboardAsSize.jsx-FF6900.svg)](https://rebrand.ly/renabsassize) [![Download](https://img.shields.io/badge/Download%20All-Zip%20archive-0088CC.svg)](https://bit.ly/2M0j95N)

The script names the artboard by its size in pixels. If you don't want save Artboard name, but replace with his size, change `var SAVE_NAME = true;` in the script file to `false`.
Renames artboards according to their size in document units.

![RenameArtboardAsSize](https://i.ibb.co/54H4Jcm/Rename-Artboard-As-Size.gif)
![RenameArtboardAsSize](https://i.ibb.co/GR488JH/Rename-Artboard-As-Size.gif)

## RenameArtboardAsTopObj
[![Direct](https://img.shields.io/badge/Direct%20Link-RenameArtboardAsTopObj.jsx-FF6900.svg)](https://rebrand.ly/renabsasobj) [![Download](https://img.shields.io/badge/Download%20All-Zip%20archive-0088CC.svg)](https://bit.ly/2M0j95N)
Expand Down
6 changes: 3 additions & 3 deletions md/Artboard.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* [FitArtboardsToArtwork](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.ru.md#fitartboardstoartwork) `upd, 18.09.2023`
* [MoveArtboards](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.ru.md#moveartboards) `upd, 04.05.2023`
* [RenameArtboardAsLayer](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.ru.md#renameartboardaslayer) `upd, 14.09.2022`
* [RenameArtboardAsSize](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.ru.md#renameartboardassize) `upd, 22.12.2022`
* [RenameArtboardAsSize](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.ru.md#renameartboardassize) `upd, 05.01.2024`
* [RenameArtboardAsTopObj](https://github.com/creold/illustrator-scripts/blob/master/md/Artboard.ru.md#renameartboardastopobj) `upd, 14.09.2022`

## ArtboardsFinder
Expand Down Expand Up @@ -95,9 +95,9 @@ Script for copying the selected Artboard with his artwork. The Pro version with
## RenameArtboardAsSize
[![Direct](https://img.shields.io/badge/Прямая%20ссылка-RenameArtboardAsSize.jsx-FF6900.svg)](https://rebrand.ly/renabsassize) [![Download](https://img.shields.io/badge/Скачать%20все-Zip--архив-0088CC.svg)](https://bit.ly/2M0j95N)

Скрипт ставит в имя артборда его размер в пикселях. Если не хотите сохранять старое имя, а только менять на размер, то откройте файл скрипта текстовым редактором и поменяйте значение в строке `var SAVE_NAME = true;` на `false`.
Добавляет к имени артборда его размеры в единицах измерения документа.

![RenameArtboardAsSize](https://i.ibb.co/54H4Jcm/Rename-Artboard-As-Size.gif)
![RenameArtboardAsSize](https://i.ibb.co/GR488JH/Rename-Artboard-As-Size.gif)

## RenameArtboardAsTopObj
[![Direct](https://img.shields.io/badge/Прямая%20ссылка-RenameArtboardAsTopObj.jsx-FF6900.svg)](https://rebrand.ly/renabsasobj) [![Download](https://img.shields.io/badge/Скачать%20все-Zip--архив-0088CC.svg)](https://bit.ly/2M0j95N)
Expand Down

0 comments on commit 977c9d3

Please sign in to comment.