Advertisement
Cronos

Illustrator Align Text Script

Jan 27th, 2013
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // script.name = alignText.jsx;
  2. // script.description = aligns selected text;
  3. // script.requirements = an open document and one or more text frames selected;
  4. // script.parent = CarlosCanto // 01/27/2013;
  5. // script.elegant = false;
  6.  
  7.  
  8. // Usage: select one or more text frames and click on any of the alignment or justification list options to align or justify
  9. //               it works with CS4 and above (not tested on earlier versions, so it may work as far as CS2)
  10. //       
  11. // Known Issues: Align Left is broken, as a workaround, try using 'Justify Last Line Left' on point text,
  12. //                              on Area text it may not be what you need.
  13.  
  14.  
  15. #target Illustrator
  16. #targetengine main
  17.  
  18. var justificationList = ["Align Left", "Align Center", "Align Right", "Justify Last Line Left", "Justify Last Line Center", "Justify Last Line Right", "Justify All Lines"];
  19.  
  20. var win = new Window('palette', 'Align Text - Keep Position', undefined, {resizeable:false});
  21. var ddL = win.add('listbox',undefined,justificationList, {multiselect: false});
  22. var msg = 'Align Left is broken, \nfor Point Text try any \nof the Justify options';
  23. var lblNote = win.add('statictext', undefined, msg, {multiline:true});
  24.  
  25. ddL.alignment = ["fill","fill"];
  26. win.preferredSize = [100,-1];
  27. win.alignChildren = ["fill", "bottom"];
  28. win.helpTip = "\u00A9 2013 Carlos Canto";
  29.  
  30. ddL.onChange = function () {
  31.     buildMsg (ddL.selection.index);
  32.     //ddL.add('separator', undefined, 3); // separator does not work in ListBox, ok in Dropdownlist
  33. }
  34.  
  35. win.onShow = function () {win.layout.resize();}
  36.  
  37. win.center();
  38. win.show();
  39.  
  40. function buildMsg (alignment) {
  41.  
  42.     var bt = new BridgeTalk;
  43.     bt.target = "illustrator";     
  44.     var params = {idx:alignment};
  45.     var msg = alignSelection + '\ralignSelection(' + params.toSource() + ');';
  46.  
  47.     bt.body = msg;
  48.     bt.send(); 
  49. }
  50.  
  51. function alignSelection (params) {
  52.     var obj = eval(params);
  53.     var justification = [Justification.LEFT, Justification.CENTER, Justification.RIGHT, Justification.FULLJUSTIFYLASTLINELEFT, Justification.FULLJUSTIFYLASTLINECENTER, Justification.FULLJUSTIFYLASTLINERIGHT, Justification.FULLJUSTIFY];
  54.     var alignment = justification[obj.idx];
  55.     var idoc = app.activeDocument;
  56.     var sel = idoc.selection;
  57.     var selen = sel.length;
  58.     for (j=0; j<selen; j++) {
  59.         var itext = sel[j];
  60.         if (itext.typename == "TextFrame") {
  61.             var pos = itext.position;
  62.             itext.textRange.paragraphAttributes.justification = alignment;
  63.             itext.position = pos;
  64.         }
  65.     }
  66.     app.redraw();
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement