Skip to main content
rcraighead
Legend
April 9, 2018
Question

Script periodically crashes AI CC 2015.3. How can I fix it?

  • April 9, 2018
  • 1 reply
  • 439 views

The script, below, is a compilation of several snippets I've gathered from this and other forums. If I used (abused) your script I truly thank you.

My question is; how can I improve it? I am running it as part of a Keyboard Maestro macro and calling it through an AppleScript (which seems to be the accepted method in Keyboard Maestro). It usually works fine, but sometimes causes AI CC 2015.3 (Mac) to crash. It also fails to perform the "AutoTrace" sequence the first time it runs after a System reboot, simply saving the bitmap image as a PDF instead.

Any suggestions for improving the script would be greatly appreciated. I'd also be very willing to hire someone to fix this and other possible scripts I need to develop.

The goal of the script is to take a Finder selection (PNG or JPG), open it in AI, perform a tracing and save a Vector PDF to the same folder as the original file.

Thanks,

Ray

var doc = app.activeDocument;

var pItems = doc.pathItems;

var Selected = doc.selection[0]

var Tracing_Preset = '[Default]'; 

var doc = app.activeDocument; 

var sel = doc.selection; 

var f =15; //percent of current size

//~ Trace Fingerprint

for(var i = 0; i<sel.length; i++){

    if(sel == '[RasterItem ]'){

        var pic = sel.trace();

        pic.tracing.tracingOptions.loadFromPreset(Tracing_Preset);

        pic.tracing.expandTracing().selected = true;

        } 

//Scale Fingerprint

for ( var i = 0; i < pItems.length; i++ ) {

    pItems.resize( f,f,true,true,true,true,f,Transformation.DOCUMENTORIGIN );

};

//~ Fit Artboard to Fingerprint

function fitArtboards() {

     if (app.documents.length == 0) {

          alert('Open a document before running this script');

               return;

     } else {

          for (var i = 0; i < documents.length; i++ ) {

               app.activeDocument = documents;

               app.activeDocument.artboards[0].artboardRect = app.activeDocument.geometricBounds;

               redraw();

          }

     }

}

fitArtboards();

//Save PDF

function test(){ 

  var doc = app.activeDocument; 

  var parentPath = Folder(File(doc.fullName).parent); 

  var opts = new PDFSaveOptions(); 

//~   opts.pDFPreset = "[Smallest File Size]"; 

  opts.pDFPreset = "[Illustrator Default]"; 

  doc.saveAs(File(parentPath + "/" + doc.name.replace(/\.\w+$/, "_Vector.pdf")), opts); 

}; 

test(); 

// Close file

if ( app.documents.length > 0 ) {

aiDocument = app.activeDocument;

aiDocument.close( SaveOptions.DONOTSAVECHANGES );

aiDocument = null;

}

This topic has been closed for replies.

1 reply

pixxxelschubser
Community Expert
Community Expert
April 9, 2018

Hi

at the beginning is missing this line:

var doc = app.activeDocument;

and

if(sel.typename == '[RasterItem ]'){

should be

if(sel.typename == 'RasterItem '){

These are the major mistakes.

The script takes a while, but it does (Illu CC under Windows 10).

rcraighead
Legend
April 9, 2018

@pixxxel

Thank you for your help! I actually do have the first line, but missed it when pasting. I'll make the correction. Thanks again.

pixxxelschubser
Community Expert
Community Expert
April 10, 2018

The bitmap is opened directly from the Finder as an embedded image. It is selected by default, but it would be good to "select all" anyway. How could I do that in the script?


rcraighead  schrieb

… but it would be good to "select all" anyway. How could I do that in the script?

app.executeMenuCommand('selectall');

Have fun