-
Notifications
You must be signed in to change notification settings - Fork 114
/
SelectAllLayersAbove.jsx
107 lines (88 loc) · 2.68 KB
/
SelectAllLayersAbove.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
102
103
104
105
106
107
/*
SelectAllLayersAbove.jsx for Adobe Illustrator
Description: Selects the contents of all layers above the active layer
Date: February, 2022
Author: Sergey Osokin, email: hi@sergosokin.ru
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 isInclActive = false; // Include the content of the active layer
if (!documents.length) {
alert('Error\nOpen a document and try again');
return;
}
if (selection.length && selection.typename !== 'TextRange') {
activeDocument.activeLayer = getParentLayer(selection[0]);
}
var layers = getLayersAbove(isInclActive);
selectAllOnLayers(layers);
}
/**
* Get all layers above the active layer
* @param {boolean} isInclActive - include the active layer
* @return {array} out - layers
*/
function getLayersAbove(isInclActive) {
var doc = activeDocument,
aLayer = getParentLayer(doc.activeLayer),
out = [];
for (var i = 0, len = doc.layers.length; i < len; i++) {
if (doc.layers[i] !== aLayer) {
if(isAvailable(doc.layers[i])) out.push(doc.layers[i]);
} else {
break;
}
}
if (isInclActive && isAvailable(aLayer)) out.push(aLayer);
return out;
}
/**
* Get the parent layer for object
* @param {object} obj - selected item or sublayer
* @return {object} parent layer
*/
function getParentLayer(obj) {
if (obj.parent.typename === 'Document') return obj;
else return getParentLayer(obj.parent);
}
/**
* Check layer availability
* @param {object} layer
* @return {boolean} layer is unlocked and visible
*/
function isAvailable(layer) {
return layer.visible && !layer.locked;
}
/**
* Select all objects on layers
* @param {array} layers
*/
function selectAllOnLayers(layers) {
if (!layers.length) return;
selection = null;
for (var i = 0, len = layers.length; i < len; i++) {
layers[i].hasSelectedArtwork = true;
}
}
// Run script
try {
main();
} catch (e) {}