Last active
December 10, 2023 00:50
-
-
Save mhulse/8061629ee2303d1bd5af to your computer and use it in GitHub Desktop.
Adobe Illustrator script to select highlighted layers. Written by @Qwertyfly and only slightly modified by me. Original code and discussion can found here: https://forums.adobe.com/message/8328893
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#target illustrator | |
function make() { | |
var name = 'temp'; // Action name. | |
var set = 'temp'; // Set name. | |
var level = app.userInteractionLevel; | |
var action; | |
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; | |
action = [ | |
'/version 3', | |
'/name [', | |
'4', // Group name character count. | |
'74656d70', // Group name as a hash. | |
']', | |
'/isOpen 0', | |
'/actionCount 1', | |
'/action-1 {', | |
'/name [', | |
'4', // Action name character count. | |
'74656d70', // Action name as a hash. | |
']', | |
'/keyIndex 0', | |
'/colorIndex 0', | |
'/isOpen 0', | |
'/eventCount 1', | |
'/event-1 {', | |
'/useRulersIn1stQuadrant 0', | |
'/internalName (ai_plugin_Layer)', | |
'/localizedName [', | |
'5', | |
'4c61796572', | |
']', | |
'/isOpen 0', | |
'/isOn 1', | |
'/hasDialog 0', | |
'/parameterCount 3', | |
'/parameter-1 {', | |
'/key 1836411236', | |
'/showInPalette -1', | |
'/type (integer)', | |
'/value 7', | |
'}', | |
'/parameter-2 {', | |
'/key 1937008996', | |
'/showInPalette -1', | |
'/type (integer)', | |
'/value 23', | |
'}', | |
'/parameter-3 {', | |
'/key 1851878757', | |
'/showInPalette -1', | |
'/type (ustring)', | |
'/value [', | |
'11', | |
'48696465204f7468657273', | |
']', | |
'}', | |
'}', | |
'}' | |
].join('\n'); | |
create(action); | |
app.doScript(name, set, false); | |
action = null; | |
app.unloadAction(set, ''); | |
app.userInteractionLevel = level; | |
} | |
function create(str) { | |
var aia = new File('~/temp.aia'); | |
aia.open('w'); | |
aia.write(str); | |
aia.close(); | |
app.loadAction(aia); | |
aia.remove(); | |
} | |
function get() { | |
var doc = app.activeDocument; | |
var layers = doc.layers; | |
var cached = []; | |
var selected = []; | |
var i; | |
// Record existing visibility: | |
for (i = 0; i < layers.length; i++) { | |
cached.push(layers[i].visible); | |
if ( ! layers[i].visible) { | |
layers[i].visible = true; | |
} | |
} | |
// Make all selected layers visible and hide the rest: | |
make(); | |
// Grab the selected visible layers: | |
for (i = 0; i < layers.length; i++) { | |
if (layers[i].visible) { | |
selected.push(layers[i]); | |
} | |
} | |
// Restore visibility: | |
for (i = 0; i < layers.length; i++) { | |
layers[i].visible = cached[i]; | |
} | |
// Return the selected layers array: | |
return selected; | |
} | |
var mylayers = get(); | |
for (var i = 0; i < mylayers.length; i++) { | |
alert(mylayers[i].name + ", " + mylayers[i].visible); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/version 3 | |
/name [ | |
4 | |
74656d70 | |
] | |
/isOpen 0 | |
/actionCount 1 | |
/action-1 { | |
/name [ | |
4 | |
74656d70 | |
] | |
/keyIndex 0 | |
/colorIndex 0 | |
/isOpen 0 | |
/eventCount 1 | |
/event-1 { | |
/useRulersIn1stQuadrant 0 | |
/internalName (ai_plugin_Layer) | |
/localizedName [ | |
5 | |
4c61796572 | |
] | |
/isOpen 0 | |
/isOn 1 | |
/hasDialog 0 | |
/parameterCount 3 | |
/parameter-1 { | |
/key 1836411236 | |
/showInPalette -1 | |
/type (integer) | |
/value 7 | |
} | |
/parameter-2 { | |
/key 1937008996 | |
/showInPalette -1 | |
/type (integer) | |
/value 23 | |
} | |
/parameter-3 { | |
/key 1851878757 | |
/showInPalette -1 | |
/type (ustring) | |
/value [ | |
11 | |
48696465204f7468657273 | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original code and discussion can found here: