Advertisement
Cronos

Illustrator Artboard Preview Script

Dec 4th, 2013
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #target Illustrator
  2.  
  3. //  script.name = artboardPreview_CS4_CS5.V1.0.jsx;
  4. //  script.description = previews the active artboard;
  5. //  script.required = an open document;
  6. //  script.parent = carlos canto // 8/30/11;
  7. //  script.elegant = false;
  8. //  script.credits = inspired by one of Mark Larsen's scripts where he used a snap shot of a selected object in the ScriptUI.
  9. //                             Script made possible by the use of Marc Autret's prototype function to resize an image to fit its container.
  10.  
  11. //  notes: not the fastest script in town, it takes a couple of seconds to capture the screen. The bigger the artboard, the longer it takes.
  12.  
  13. //  Mac users: ************************** Press Esc key to dismiss *************************************** , windows too in fact.
  14.  
  15. if (app.documents.length > 0)
  16.     {
  17.         // thanks to Marc for writing this amazing function prototype
  18.         Image.prototype.onDraw = function()
  19.             { // written by Marc Autret
  20.                 // "this" is the container; "this.image" is the graphic
  21.                 if( !this.image ) return;
  22.                 var WH = this.size,
  23.                 wh = this.image.size,
  24.                 k = Math.min(WH[0]/wh[0], WH[1]/wh[1]),
  25.                 xy;
  26.                 // Resize proportionally:
  27.                 wh = [k*wh[0],k*wh[1]];
  28.                 // Center:
  29.                 xy = [ (WH[0]-wh[0])/2, (WH[1]-wh[1])/2 ];
  30.                 this.graphics.drawImage(this.image,xy[0],xy[1],wh[0],wh[1]);
  31.                 WH = wh = xy = null;
  32.             }
  33.  
  34.         var idoc = app.activeDocument;
  35.         var img = File('~/Desktop/tempCapture.png'); // image place holder
  36.  
  37.         var captureOpts = new ImageCaptureOptions; // declare capture options, needed to trun on anti-alias
  38.         captureOpts.matte = true; // to give transparent areas some color. default is white.
  39.         captureOpts.antiAliasing = true; // anti-alias the image
  40.         idoc.imageCapture (img, idoc.artboards[idoc.artboards.getActiveArtboardIndex()].artboardRect,captureOpts); // capture the active artboard
  41.  
  42.         var w = new Window('dialog','Preview active Artboard - Press Esc key to close'); // create a dialog
  43.  
  44.         var scr = $.screens[0]; // array of screens, my laptop = screen[0]
  45.         var width = scr.right-scr.left; // get max width
  46.         var height = scr.bottom - scr.top; // get max height
  47.        
  48.         w.size = [width, height]; // size the window
  49.  
  50.         //var img = File.openDialog ('select file'); // debug test different images
  51.         var imgFrame = w.add('image',undefined,img); // add image container
  52.         imgFrame.helpTip = 'Coded by CarlosCanto';
  53.         imgFrame.title = 'Press Esc key to close';
  54.         imgFrame.titleLayout = { alignment: ['center', 'center'] };
  55.        
  56.         imgFrame.size = [width-100,height-80]; // size container, a tad smaller than the window
  57.        
  58.         w.show();
  59.      }
  60.  else
  61.     {
  62.         alert ("there are no open documents to preview");
  63.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement