Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // script.name = alignText.jsx;
- // script.description = aligns selected text;
- // script.requirements = an open document and one or more text frames selected;
- // script.parent = CarlosCanto // 01/27/2013;
- // script.elegant = false;
- // Usage: select one or more text frames and click on any of the alignment or justification list options to align or justify
- // it works with CS4 and above (not tested on earlier versions, so it may work as far as CS2)
- //
- // Known Issues: Align Left is broken, as a workaround, try using 'Justify Last Line Left' on point text,
- // on Area text it may not be what you need.
- #target Illustrator
- #targetengine main
- var justificationList = ["Align Left", "Align Center", "Align Right", "Justify Last Line Left", "Justify Last Line Center", "Justify Last Line Right", "Justify All Lines"];
- var win = new Window('palette', 'Align Text - Keep Position', undefined, {resizeable:false});
- var ddL = win.add('listbox',undefined,justificationList, {multiselect: false});
- var msg = 'Align Left is broken, \nfor Point Text try any \nof the Justify options';
- var lblNote = win.add('statictext', undefined, msg, {multiline:true});
- ddL.alignment = ["fill","fill"];
- win.preferredSize = [100,-1];
- win.alignChildren = ["fill", "bottom"];
- win.helpTip = "\u00A9 2013 Carlos Canto";
- ddL.onChange = function () {
- buildMsg (ddL.selection.index);
- //ddL.add('separator', undefined, 3); // separator does not work in ListBox, ok in Dropdownlist
- }
- win.onShow = function () {win.layout.resize();}
- win.center();
- win.show();
- function buildMsg (alignment) {
- var bt = new BridgeTalk;
- bt.target = "illustrator";
- var params = {idx:alignment};
- var msg = alignSelection + '\ralignSelection(' + params.toSource() + ');';
- bt.body = msg;
- bt.send();
- }
- function alignSelection (params) {
- var obj = eval(params);
- var justification = [Justification.LEFT, Justification.CENTER, Justification.RIGHT, Justification.FULLJUSTIFYLASTLINELEFT, Justification.FULLJUSTIFYLASTLINECENTER, Justification.FULLJUSTIFYLASTLINERIGHT, Justification.FULLJUSTIFY];
- var alignment = justification[obj.idx];
- var idoc = app.activeDocument;
- var sel = idoc.selection;
- var selen = sel.length;
- for (j=0; j<selen; j++) {
- var itext = sel[j];
- if (itext.typename == "TextFrame") {
- var pos = itext.position;
- itext.textRange.paragraphAttributes.justification = alignment;
- itext.position = pos;
- }
- }
- app.redraw();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement