-
Notifications
You must be signed in to change notification settings - Fork 114
/
GrayscaleToOpacity.jsx
executable file
·71 lines (59 loc) · 1.87 KB
/
GrayscaleToOpacity.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
/*
GrayscaleToOpacity.jsx for Adobe Illustrator
Description: Convert selection colors to Grayscale and set identical Opacity value
Date: February, 2019
Author: Sergey Osokin, email: hi@sergosokin.ru
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() {
if (!documents.length) return;
var doc = activeDocument,
selArray = [];
app.executeMenuCommand('Colors7');
getPaths(selection, selArray);
for (var i = 0, selLen = selArray.length; i < selLen; i++) {
var value = selArray[i].fillColor.gray;
selArray[i].opacity = value.toFixed(0);
}
// Get paths from selection
function getPaths(item, arr) {
for (var i = 0, iLen = item.length; i < iLen; i++) {
var currItem = item[i];
try {
switch (currItem.typename) {
case 'GroupItem':
getPaths(currItem.pageItems, arr);
break;
case 'PathItem':
arr.push(currItem);
break;
case 'CompoundPathItem':
getPaths(currItem.pathItems, arr);
break;
default:
currItem.selected = false;
break;
}
} catch (e) {}
}
}
}
// Run script
try {
main();
} catch (e) {}