Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #target Illustrator
- // script.name = artboardPreview_CS4_CS5.V1.0.jsx;
- // script.description = previews the active artboard;
- // script.required = an open document;
- // script.parent = carlos canto // 8/30/11;
- // script.elegant = false;
- // script.credits = inspired by one of Mark Larsen's scripts where he used a snap shot of a selected object in the ScriptUI.
- // Script made possible by the use of Marc Autret's prototype function to resize an image to fit its container.
- // 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.
- // Mac users: ************************** Press Esc key to dismiss *************************************** , windows too in fact.
- if (app.documents.length > 0)
- {
- // thanks to Marc for writing this amazing function prototype
- Image.prototype.onDraw = function()
- { // written by Marc Autret
- // "this" is the container; "this.image" is the graphic
- if( !this.image ) return;
- var WH = this.size,
- wh = this.image.size,
- k = Math.min(WH[0]/wh[0], WH[1]/wh[1]),
- xy;
- // Resize proportionally:
- wh = [k*wh[0],k*wh[1]];
- // Center:
- xy = [ (WH[0]-wh[0])/2, (WH[1]-wh[1])/2 ];
- this.graphics.drawImage(this.image,xy[0],xy[1],wh[0],wh[1]);
- WH = wh = xy = null;
- }
- var idoc = app.activeDocument;
- var img = File('~/Desktop/tempCapture.png'); // image place holder
- var captureOpts = new ImageCaptureOptions; // declare capture options, needed to trun on anti-alias
- captureOpts.matte = true; // to give transparent areas some color. default is white.
- captureOpts.antiAliasing = true; // anti-alias the image
- idoc.imageCapture (img, idoc.artboards[idoc.artboards.getActiveArtboardIndex()].artboardRect,captureOpts); // capture the active artboard
- var w = new Window('dialog','Preview active Artboard - Press Esc key to close'); // create a dialog
- var scr = $.screens[0]; // array of screens, my laptop = screen[0]
- var width = scr.right-scr.left; // get max width
- var height = scr.bottom - scr.top; // get max height
- w.size = [width, height]; // size the window
- //var img = File.openDialog ('select file'); // debug test different images
- var imgFrame = w.add('image',undefined,img); // add image container
- imgFrame.helpTip = 'Coded by CarlosCanto';
- imgFrame.title = 'Press Esc key to close';
- imgFrame.titleLayout = { alignment: ['center', 'center'] };
- imgFrame.size = [width-100,height-80]; // size container, a tad smaller than the window
- w.show();
- }
- else
- {
- alert ("there are no open documents to preview");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement