-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathSelectRotatedItems.jsx
101 lines (85 loc) · 2.84 KB
/
SelectRotatedItems.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
SelectRotatedItems.jsx for Adobe Illustrator
Description: Select all editable objects in the document with a rotation angle other than zero radians
Date: June, 2022
Author: Sergey Osokin, email: [email protected]
Installation: https://github.com/creold/illustrator-scripts#how-to-run-scripts
Release notes:
0.1 Initial version
Donate (optional):
If you find this script helpful, you can buy me a coffee
- via Buymeacoffee: https://www.buymeacoffee.com/aiscripts
- via Donatty https://donatty.com/sergosokin
- via DonatePay https://new.donatepay.ru/en/@osokin
- via YooMoney https://yoomoney.ru/to/410011149615582
NOTICE:
Tested with Adobe Illustrator CC 2019-2025 (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
Check my other scripts: https://github.com/creold
*/
//@target illustrator
app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix drag and drop a .jsx file
// Main function
function main() {
var CFG = {
round: (parseInt(app.version) < 24) ? 2 : 3, // Angle value precision
isSkipRight: true // Skip right & straight angles: 90, 180, 270 degrees
};
if (!documents.length) {
alert('Error\nOpen a document and try again');
return;
}
if (!activeDocument.pageItems.length) {
alert('Error\nThe document is empty');
return;
}
var items = (selection.length) ? getItems(selection) : getLayerItems(activeDocument.layers);
rotItems = getRotated(items, CFG.round, CFG.isSkipRight);
selection = rotItems;
}
// Get single items
function getItems(collection) {
var out = [];
for (var i = 0, len = collection.length; i < len; i++) {
var item = collection[i];
if (item.pageItems && item.pageItems.length) {
out = [].concat(out, getItems(item.pageItems));
} else if (item.editable) {
out.push(item);
}
}
return out;
}
// Get items in editable Layers & Sublayers
function getLayerItems(layers) {
var out = [];
for (var i = 0, len = layers.length; i < len; i++) {
var layer = layers[i];
if (layer.visible && !layer.locked) {
out = [].concat(out, getItems(layer.pageItems));
if (layer.layers.length) out = [].concat(out, getItems(layer.layers));
}
}
return out;
}
// Check the angle value in the Transform panel
function getRotated(items, round, isSkip) {
var out = [];
for (var i = 0, len = items.length; i < len; i++) {
try {
var rotInfo = items[i].tags['BBAccumRotation'],
angle = 1 * (rotInfo.value * (180 / Math.PI)).toFixed(round); // Radians to degrees
if ((!isSkip && angle !== 0) || (isSkip && !/(0|90|180|270)$/.test(angle))) {
out.push(items[i]);
}
} catch(e) {}
}
return out;
}
// Run script
try {
main();
} catch (e) {}