Advertisement
Cronos

Illustrator Select Layers Script

Nov 2nd, 2012
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // script.name = selectLayers.jsx;
  2. // script.description = selects layers;
  3. // script.requirements = an opened document;
  4. // script.parent = CarlosCanto // 10/29/2012;
  5. // script.elegant = false;
  6.  
  7.  
  8. // Usage: select single layers by selecting them then clicking on the "select" button or by double clicking on them
  9. //               select multiple contiguos layers by clicking on the first layer, then holding Shift, clicking on the last one
  10. //        select multiple non-contiguos layers by clicking on them while holding Ctrl
  11.  
  12.  
  13. #target Illustrator
  14. #targetengine main
  15.  
  16. var idoc = app.activeDocument;
  17. var layers = idoc.layers;
  18. var layerCount = layers.length;
  19. var layerNames = [];    
  20. for (i=0; i<layerCount; i++) {
  21.     layerNames[i] = layers[i].name;
  22. }
  23.  
  24. var win = new Window('palette', 'Select Layers', undefined, {resizeable:true});
  25. var ddL = win.add('listbox',undefined,layerNames, {multiselect: true});
  26. var btnSelect = win.add('button', undefined, 'Select');
  27.  
  28. ddL.alignment = ["fill","fill"];
  29. win.preferredSize = [100,-1];
  30. win.alignChildren = ["fill", "bottom"];
  31. win.helpTip = "\u00A9 2012 Carlos Canto";
  32. btnSelect.helpTip = "Press Esc to Close";
  33.  
  34. ddL.onDoubleClick = function () {
  35.     buildMsg (ddL.selection);
  36. }
  37. btnSelect.onClick = function(){
  38.     buildMsg (ddL.selection);    
  39. }
  40.  
  41. win.onResizing = function () {this.layout.resize();}
  42. win.onShow = function () {win.layout.resize();}
  43.  
  44. win.center();
  45. win.show();
  46.  
  47. function buildMsg (selection) {
  48.     layerList = [];
  49.     for (k=0; k<selection.length; k++)
  50.         layerList.push (selection[k].index);
  51.  
  52.     var bt = new BridgeTalk;
  53.     bt.target = "illustrator";     
  54.     var params = {layerList:layerList};
  55.     var msg = selectLayers + '\rselectLayers(' + params.toSource() + ');';
  56.  
  57.     bt.body = msg;
  58.     bt.send(); 
  59. }
  60.  
  61. function selectLayers (params) {
  62.     var obj = eval(params);
  63.     var layerList = obj.layerList;
  64.     var idoc = app.activeDocument;
  65.     for (j=0; j<layerList.length; j++) {
  66.         idoc.layers[layerList[j]].hasSelectedArtwork = true;
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement