Copy link to clipboard
Copied
is there a way to extend existing classes? I am trying to add methods to the symbolItems class, but it doesn't seem to work. says it is not defined:
symbolItems.prototype.isIn = function(parentItem, runThis) {
//do something
}
You can extend the classes by prototyping it's something I have avoided so far but have seen other AI scripts where it has been used without issue though…
Copy link to clipboard
Copied
Not as far as I know. AI scripting is pretty basic.
Copy link to clipboard
Copied
You can extend the classes by prototyping it's something I have avoided so far but have seen other AI scripts where it has been used without issue though…
Copy link to clipboard
Copied
You're right, Mark. I found one of Carlos's scripts with a prototype class extension.
#target Illustrator
// script.name = preview_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");
}
Copy link to clipboard
Copied
hmm symbolItems doesn't seem to be extendable, unless they name it something else? any ideas how I could try to extend it. example above I gave does not work.
Copy link to clipboard
Copied
Should be Class not Collection. Try this:
SymbolItem.prototype.isIn = function(parentItem, runThis) {
//do something
}