Advertisement
Cronos

Illustrator Scale Strokes Script

May 7th, 2012
752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // script.name = scaleStrokes.jsx;
  2. // script.description = scales selected objects strokes only;
  3. // script.required = one or more selected objects
  4. // script.parent = CarlosCanto // 5/7/12;
  5. // script.elegant = false;
  6.  
  7. // script.updates = preview ON by default // 5/7/12
  8.  
  9. #target Illustrator
  10.  
  11. var idoc = activeDocument;
  12. var sel = idoc.selection;
  13. var unscale = 0;
  14. if (sel.length>0) {
  15.     var win = new Window("dialog", "Scale Strokes");
  16.     var pnlScale = win.add("panel");
  17.     pnlScale.orientation = "row";
  18.     var lblScale = pnlScale.add("statictext",undefined,"Scale");
  19.     var editScale = pnlScale.add("edittext",undefined,"100");
  20.     editScale.characters = 5;
  21.     var lblScale = pnlScale.add("statictext",undefined,"%");
  22.  
  23.     var grpScroll = win.add("group");
  24.     var scrlScale = grpScroll.add("scrollbar", undefined,100, 1, 1000); // 1 min scaling to avoid division by zero
  25.  
  26.     var grpBottom = win.add("group");
  27.     grpBottom.alignChildren = "top";
  28.     var chkpreview = grpBottom.add("checkbox", undefined, "Preview");
  29.     chkpreview.value = 1;
  30.     var grpButtons = grpBottom.add("group");
  31.     grpButtons.orientation = "column";
  32.     var btnOk = grpButtons.add("button", undefined, "Ok");
  33.     var btnCancel = grpButtons.add("button", undefined, "Cancel");
  34.    
  35.     win.helpTip = grpBottom.helpTip = "\u00A9 2012 Carlos Canto";
  36.  
  37.     scrlScale.onChanging = function() {
  38.         editScale.text = this.value; // update edit box with scroll value
  39.         scaleStrokes (sel,editScale.text); // and do the scaling as the scroll changes
  40.     }
  41.  
  42.     editScale.onChange = function() {
  43.         if (this.text<1) // if value entered by hand is less than 1, make it 1 to avoid division by zero
  44.             this.text = 1;
  45.         scrlScale.value = this.text; // update edit box with scroll value
  46.         scaleStrokes (sel,editScale.text); // and do the scaling after the edit box changes (manually entering values)
  47.     }
  48.  
  49.     chkpreview.onClick = function () {
  50.         if (chkpreview.value)
  51.             app.redraw();
  52.     }
  53.    
  54.     // unscale (back to 100%) on cancel, except no scaling has applied
  55.     btnCancel.onClick = function() {
  56.         if (unscale != 0) {
  57.             unscaleStrokes (sel, unscale);
  58.         }
  59.         win.close();
  60.     }
  61.  
  62.     win.center();
  63.     win.show();
  64. }
  65. else {
  66.     alert("select at least one object before running");
  67. }
  68.  
  69. function scaleStrokes (sel,scale) {
  70.     // skip unscaling the first time, there's nothing to unscale
  71.     if (unscale != 0) {
  72.         unscaleStrokes (sel, unscale);
  73.     }
  74.     for (i=0; i<sel.length; i++) {
  75.         var pgitem = sel[i];
  76.         pgitem.resize(100, 100, undefined, undefined, undefined, undefined, scale, Transformation.CENTER);
  77.     }
  78.     if (chkpreview.value)
  79.         app.redraw();
  80.     unscale = 10000/scale;
  81. }
  82.  
  83. // unscale or bring back selection to 100%
  84. function unscaleStrokes (sel,unscale) {
  85.     for (j=0; j<sel.length; j++) {
  86.         var pgitem = sel[j];
  87.         pgitem.resize(100, 100, undefined, undefined, undefined, undefined, unscale, Transformation.CENTER);
  88.     }
  89.     if (chkpreview.value)
  90.         app.redraw();
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement