Skip to content

Commit

Permalink
Updated FitSelectionToArtboards, RenameItems, SelectBySwatches
Browse files Browse the repository at this point in the history
  • Loading branch information
creold committed Apr 22, 2024
1 parent ff18283 commit 8bd55e8
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 83 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ Click the category name to learn more about the scripts in the selected category
* [AlignToArtboards](https://github.com/creold/illustrator-scripts/blob/master/md/Item.md#aligntoartboards) `upd, 06.11.2023`
* [BatchTrace](https://github.com/creold/illustrator-scripts/blob/master/md/Item.md#batchtrace) `upd, 07.06.2023`
* [DuplicateToArtboards](https://github.com/creold/illustrator-scripts/blob/master/md/Item.md#duplicatetoartboards) `upd, 09.02.2024`
* [FitSelectionToArtboards](https://github.com/creold/illustrator-scripts/blob/master/md/Item.md#fitselectiontoartboards) `upd, 06.11.2023`
* [FitSelectionToArtboards](https://github.com/creold/illustrator-scripts/blob/master/md/Item.md#fitselectiontoartboards) `upd, 22.04.2024`
* [MakeEnvelopesWithTops](https://github.com/creold/illustrator-scripts/blob/master/md/Item.md#makeenvelopeswithtops)
* [MirrorMove](https://github.com/creold/illustrator-scripts/blob/master/md/Item.md#mirrormove) `upd, 01.08.2022`
* [RenameItems](https://github.com/creold/illustrator-scripts/blob/master/md/Item.md#renameitems) `upd, 09.02.2024`
* [RenameItems](https://github.com/creold/illustrator-scripts/blob/master/md/Item.md#renameitems) `upd, 22.04.2024`
* [Rescale](https://github.com/creold/illustrator-scripts/blob/master/md/Item.md#rescale) `upd, 09.02.2024`
* [ResizeOnLargerSide](https://github.com/creold/illustrator-scripts/blob/master/md/Item.md#resizeonlargerside) `upd, 22.12.2022`
* [ResizeToSize](https://github.com/creold/illustrator-scripts/blob/master/md/Item.md#resizetosize) `upd, 09.02.2024`
Expand Down Expand Up @@ -165,7 +165,7 @@ Click the category name to learn more about the scripts in the selected category
* [NamedItemsFinder](https://github.com/creold/illustrator-scripts/blob/master/md/Select.md#named-items-finder) `upd, 09.02.2024`
* [SelectAllLayersAbove](https://github.com/creold/illustrator-scripts/blob/master/md/Select.md#selectalllayersabove) `21.02.2022`
* [SelectAllLayersBelow](https://github.com/creold/illustrator-scripts/blob/master/md/Select.md#selectalllayersabove) `21.02.2022`
* [SelectBySwatches](https://github.com/creold/illustrator-scripts/blob/master/md/Select.md#selectbyswatches) `upd, 09.02.2024`
* [SelectBySwatches](https://github.com/creold/illustrator-scripts/blob/master/md/Select.md#selectbyswatches) `upd, 22.04.2024`
* [SelectOnlyPoints](https://github.com/creold/illustrator-scripts/blob/master/md/Select.md#selectonlypoints)
* [SelectPointsByType](https://github.com/creold/illustrator-scripts/blob/master/md/Select.md#selectpointsbytype) `upd, 09.02.2024`
* [SelectRotatedItems](https://github.com/creold/illustrator-scripts/blob/master/md/Select.md#selectrotateditems) `22.06.2022`
Expand Down
6 changes: 3 additions & 3 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@
* [AlignToArtboards](https://github.com/creold/illustrator-scripts/blob/master/md/Item.ru.md#aligntoartboards) `upd, 06.11.2023`
* [BatchTrace](https://github.com/creold/illustrator-scripts/blob/master/md/Item.ru.md#batchtrace) `upd, 07.06.2023`
* [DuplicateToArtboards](https://github.com/creold/illustrator-scripts/blob/master/md/Item.ru.md#duplicatetoartboards) `upd, 09.02.2024`
* [FitSelectionToArtboards](https://github.com/creold/illustrator-scripts/blob/master/md/Item.ru.md#fitselectiontoartboards) `upd, 06.11.2023`
* [FitSelectionToArtboards](https://github.com/creold/illustrator-scripts/blob/master/md/Item.ru.md#fitselectiontoartboards) `upd, 22.04.2024`
* [MakeEnvelopesWithTops](https://github.com/creold/illustrator-scripts/blob/master/md/Item.ru.md#makeenvelopeswithtops)
* [MirrorMove](https://github.com/creold/illustrator-scripts/blob/master/md/Item.ru.md#mirrormove) `upd, 01.08.2022`
* [RenameItems](https://github.com/creold/illustrator-scripts/blob/master/md/Item.ru.md#renameitems) `upd, 09.02.2024`
* [RenameItems](https://github.com/creold/illustrator-scripts/blob/master/md/Item.ru.md#renameitems) `upd, 22.04.2024`
* [Rescale](https://github.com/creold/illustrator-scripts/blob/master/md/Item.ru.md#rescale) `upd, 09.02.2024`
* [ResizeOnLargerSide](https://github.com/creold/illustrator-scripts/blob/master/md/Item.ru.md#resizeonlargerside) `upd, 22.12.2022`
* [ResizeToSize](https://github.com/creold/illustrator-scripts/blob/master/md/Item.ru.md#resizetosize) `upd, 09.02.2024`
Expand Down Expand Up @@ -174,7 +174,7 @@
* [NamedItemsFinder](https://github.com/creold/illustrator-scripts/blob/master/md/Select.ru.md#named-items-finder) `upd, 09.02.2024`
* [SelectAllLayersAbove](https://github.com/creold/illustrator-scripts/blob/master/md/Select.ru.md#selectalllayersabove) `21.02.2022`
* [SelectAllLayersBelow](https://github.com/creold/illustrator-scripts/blob/master/md/Select.ru.md#selectalllayersabove) `21.02.2022`
* [SelectBySwatches](https://github.com/creold/illustrator-scripts/blob/master/md/Select.ru.md#selectbyswatches) `upd, 09.02.2024`
* [SelectBySwatches](https://github.com/creold/illustrator-scripts/blob/master/md/Select.ru.md#selectbyswatches) `upd, 22.04.2024`
* [SelectOnlyPoints](https://github.com/creold/illustrator-scripts/blob/master/md/Select.ru.md#selectonlypoints)
* [SelectPointsByType](https://github.com/creold/illustrator-scripts/blob/master/md/Select.ru.md#selectpointsbytype) `upd, 09.02.2024`
* [SelectRotatedItems](https://github.com/creold/illustrator-scripts/blob/master/md/Select.ru.md#selectrotateditems) `22.06.2022`
Expand Down
22 changes: 11 additions & 11 deletions jsx/FitSelectionToArtboards-Lite.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
FitSelectionToArtboards-Lite.jsx for Adobe Illustrator
Description: Proportional resizing one selected object to fit in parent artboard
Date: July, 2022
Modification date: September, 2023
Modification date: April, 2024
Author: Sergey Osokin, email: hi@sergosokin.ru
Full version: https://github.com/creold/illustrator-scripts/blob/master/md/Item.md#fitselectiontoartboards
Installation: https://github.com/creold/illustrator-scripts#how-to-run-scripts
Release notes:
0.1 Initial version
0.1.2 Fixed objects alignment with modified artboard rulers
0.1.1 Fixed text object fitting
0.1 Initial version
Donate (optional):
If you find this script helpful, you can buy me a coffee
Expand All @@ -20,7 +21,7 @@
- via YooMoney https://yoomoney.ru/to/410011149615582
NOTICE:
Tested with Adobe Illustrator CC 2018-2022 (Mac), 2022 (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
Expand All @@ -42,10 +43,6 @@ function main() {
aiVers: parseInt(app.version),
};

var isRulerTopLeft = preferences.getBooleanPreference('isRulerOriginTopLeft'),
isRulerInFourthQuad = preferences.getBooleanPreference('isRulerIn4thQuad');
CFG.isFlipY = (isRulerTopLeft && isRulerInFourthQuad) ? true : false;

if (CFG.aiVers < 16) {
alert('Error\nSorry, script only works in Illustrator CS6 and later', 'Script error');
return;
Expand All @@ -65,16 +62,19 @@ function main() {
abIdx = doc.artboards.getActiveArtboardIndex(),
abBnds = doc.artboards[abIdx].artboardRect,
item = selection[0],
coord = app.coordinateSystem;
coord = app.coordinateSystem,
ruler = doc.artboards[abIdx].rulerOrigin;

// If the active artboard contains the selected object
if (!CFG.isContains || isContains(item, CFG.tag)) {
app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;
doc.artboards[abIdx].rulerOrigin = [0, 0];

fitToArtboard(item, abBnds, CFG.visBnds, CFG.isScaleStroke);
centerToArtboard(item, abBnds, CFG.isFlipY);
centerToArtboard(item, abBnds);

app.coordinateSystem = coord;
doc.artboards[abIdx].rulerOrigin = ruler;
}

selection = [item];
Expand Down Expand Up @@ -238,7 +238,7 @@ function getVisibleBounds(obj, type) {
}

// Place the item in the center of the artboard
function centerToArtboard(item, abBnds, isFlipY) {
function centerToArtboard(item, abBnds) {
var bnds = item.geometricBounds,
itemSize = {
left: bnds[0],
Expand Down Expand Up @@ -280,7 +280,7 @@ function centerToArtboard(item, abBnds, isFlipY) {
var left = itemSize.left - itemSize.inLeft,
top = itemSize.top - itemSize.inTop,
centerX = left + (abWidth - itemSize.w) / 2,
centerY = top + (itemSize.h + (isFlipY ? -1 : 1) * abHeight) / 2;
centerY = top + (itemSize.h - abHeight) / 2;

item.position = [centerX, centerY];
}
Expand Down
44 changes: 24 additions & 20 deletions jsx/FitSelectionToArtboards.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
FitSelectionToArtboards.jsx for Adobe Illustrator
Description: Proportional resizing of objects to fit one in each artboard
Date: December, 2022
Modification date: September, 2023
Modification date: April, 2024
Author: Sergey Osokin, email: hi@sergosokin.ru
Installation: https://github.com/creold/illustrator-scripts#how-to-run-scripts
Release notes:
0.1 Initial version
0.2 Added more options
0.3 Added silent mode when holding the Alt key
0.3.1 Added size correction in large canvas mode
0.3.2 Added new units API for CC 2023 v27.1.1
0.3.4 Fixed objects alignment with modified artboard rulers
0.3.3 Fixed text object fitting
0.3.2 Added new units API for CC 2023 v27.1.1
0.3.1 Added size correction in large canvas mode
0.3 Added silent mode when holding the Alt key
0.2 Added more options
0.1 Initial version
Donate (optional):
If you find this script helpful, you can buy me a coffee
Expand All @@ -23,7 +24,7 @@
- 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
Expand All @@ -39,7 +40,7 @@ preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix drag a
function main() {
var SCRIPT = {
name: 'Fit Selection To Artboards',
version: 'v.0.3.3'
version: 'v.0.3.4'
},
CFG = {
pads: 0,
Expand Down Expand Up @@ -73,10 +74,6 @@ function main() {
// Scale factor for Large Canvas mode
CFG.sf = activeDocument.scaleFactor ? activeDocument.scaleFactor : 1;

var isRulerTopLeft = preferences.getBooleanPreference('isRulerOriginTopLeft'),
isRulerInFourthQuad = preferences.getBooleanPreference('isRulerIn4thQuad');
CFG.isFlipY = (isRulerTopLeft && isRulerInFourthQuad) ? true : false;

var isAltPressed = false;
if (ScriptUI.environment.keyboardState.altKey) isAltPressed = true;

Expand Down Expand Up @@ -173,15 +170,18 @@ function process(cfg) {
abBnds = docAbs[abIdx].artboardRect,
docSel = selection,
item = docSel[0],
coord = app.coordinateSystem;
coord = app.coordinateSystem,
ruler = docAbs[abIdx].rulerOrigin;

app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;

if (!cfg.isAll) {
if (cfg.isFit) {
fitToArtboard(item, abBnds, cfg.isVisBnds, cfg.isScaleStroke, cfg.pads);
}
centerToArtboard(item, abBnds, cfg.isFlipY);
docAbs[abIdx].rulerOrigin = [0, 0];
centerToArtboard(item, abBnds);
docAbs[abIdx].rulerOrigin = ruler;
if (cfg.isRename) {
renameArtboard(item, docAbs[abIdx]);
}
Expand All @@ -191,14 +191,18 @@ function process(cfg) {

for (var i = len - 1; i >= 0; i--) {
item = docSel[i];
abBnds = docAbs[emptyAbs[i]].artboardRect;
docAbs.setActiveArtboardIndex(emptyAbs[i]);
abIdx = emptyAbs[i];
abBnds = docAbs[abIdx].artboardRect;
docAbs.setActiveArtboardIndex(abIdx);
if (cfg.isFit) {
fitToArtboard(item, abBnds, cfg.isVisBnds, cfg.isScaleStroke, cfg.pads);
}
centerToArtboard(item, abBnds, cfg.isFlipY);
ruler = docAbs[abIdx].rulerOrigin;
docAbs[abIdx].rulerOrigin = [0, 0];
centerToArtboard(item, abBnds);
docAbs[abIdx].rulerOrigin = ruler;
if (cfg.isRename) {
renameArtboard(item, docAbs[emptyAbs[i]]);
renameArtboard(item, docAbs[abIdx]);
}
}
}
Expand Down Expand Up @@ -365,7 +369,7 @@ function getVisibleBounds(obj, type) {
}

// Place the item in the center of the artboard
function centerToArtboard(item, abBnds, isFlipY) {
function centerToArtboard(item, abBnds) {
var bnds = item.geometricBounds,
itemSize = {
left: bnds[0],
Expand Down Expand Up @@ -407,7 +411,7 @@ function centerToArtboard(item, abBnds, isFlipY) {
var left = itemSize.left - itemSize.inLeft,
top = itemSize.top - itemSize.inTop,
centerX = left + (abWidth - itemSize.w) / 2,
centerY = top + (itemSize.h + (isFlipY ? -1 : 1) * abHeight) / 2;
centerY = top + (itemSize.h - abHeight) / 2;

item.position = [centerX, centerY];
}
Expand Down
Loading

0 comments on commit 8bd55e8

Please sign in to comment.