Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all 12845 articles
Browse latest View live

Transform Each

$
0
0

Hi all,

 

i'm working on a script and final step is missing, i just want to know Transform each function code on JavaScript, or at least i want to create a code can do a shortcut like (Alt+Ctrl+Shift+D)

 

 

Object > Transform > Transform Each with Reflect X and Center point position

 

image.png

 

 

7.png

 

 

is it possible??

 

 

Thanks a lot

 


Illustrator Scripting Panel

$
0
0

Just thought I'd share an extension I've been tinkering with:

 

GitHub - majman/adobe-scripts-panel: Scripting Panel for Adobe Illustrator

 

It's a pretty simple panel that allows you to try snippets of code in the editor, list and run saved scripts from your local files, or even load and run scripts from the web.

 

Hope somebody finds it helpful. Feel free to fork the repo and send pull requests.

 

-Marshall

VB.net scaling / Resize and export as SVG

$
0
0

Hi,

 

I'm using Illustrator CS4 and VB.NET 2008.

 

I'm doing a fairly simple operation in VB.net using Illustrator.  I load an  .AI file that was saved out of Illustrator and then resave it as a SVG file.  This works fine.

 

I need to scale up the SVG since for whatever reason the SVG artwork is smaller than the AI file.    This happens even if you just save the SVG file straight out of CS2/CS3/CS4/CS5 not using any automation.  Must be a feature, not a bug.

 

Anyway, I am able to set the scalematrix but for whatever reason, when I try to apply it, I can't get the syntax or object reference right.

 

I've looked at the illustrator CS4 Scripting reference(see below) and it says " artItem.Transform totalMatrix".  If I use that syntax  VB.net complains that the "Method arguments must be enclosed in parethesis"

 

If I enclose it,Like this: artitem.Transform(scalematrix)

 

I get this Warning     "Variable 'artitem' is used before it has been assigned a value. A null reference exception could result at runtime. "  and of course, at run time it barfs with a null exception.

 

Any suggestions?  I've dug through the illustrator objects trying to see if I've defined artitem wrong or something.  I'm stuck.

 

Thanks,

 

Mark


 

---------

 

      Dim illusapp As New Illustrator.Application
      Dim illusdoc As Illustrator.Document
      Dim scalematrix As Illustrator.Matrix
      Dim artitem As Illustrator.PathItem
      illusapp.UserInteractionLevel = Illustrator.AiUserInteractionLevel.aiDontDisplayAlerts
      
      Dim svgOpt = new illustrator.ExportOptionsSVG
      svgOpt.DTD = Illustrator.AiSVGDTDVersion.aiSVG1_0   

 

            illusdoc = illusapp.Open("c:\test\test.ai")

 

            scalematrix = illusapp.GetScaleMatrix(125,125)

'------ Problem starts here.

            artitem.transform(totalmatrix)
'------ Problem ends here.

 

            illusdoc.Export("c:\test\test.svg",Illustrator.AiExportType.aiSVG,svgopt)
            illusdoc.Close

 

-------

From Adobe Illustrator CS4 Scripting Reference.

     Applying transformations with a matrix
'Creates a new translation and rotation matrix then
'applies it to all items in the current document


Set appRef = CreateObject("Illustrator.Application")

 

'Move art half an inch to the right and 1.5 inch up on the page

 

     Set moveMatrix = appRef.GetTranslationMatrix(72 * 0.5, 72 * 1.5)

 

'Add a rotation to the translation -- 10 degrees counterclockwise

 

     Set totalMatrix = appRef.ConcatenateRotationMatrix(moveMatrix, 10)

 

'Apply the transformation to all art in the document

 

For Each artItem In appRef.ActiveDocument.PageItems
     artItem.Transform totalMatrix
Next

Advanced "Save as PDF" script that saves 2 PDF presets with 2 different names.

$
0
0

Hi Everyone,

 

I am looking to improve a save as pdf workflow and was hoping to get some direction. Here is the background...

 

I routinely have to save numerous files as 2 separate PDFs with different settings (a high res printable version and a low res email version). Each file has to be renamed as follows...

 

Original filename = MikesPDF.ai

High Res PDF Filename = MikesPDF_HR.pdf

Low Res PDF Filename = MikesPDF_LR.pdf

 

I was able to alter the default "SaveAsPDF" script to save the files to my desired settings and to add the suffix to the name. So with these scripts here is how the workflow operates...

 

1. Open all files I wish to save as pdfs

2. Select script to save files as high res pdfs

3. Illustrator asks me to choose a destination.

4. Illustrator adds the appropriate suffix and saves each file as a pdf to my desired setting. ("Save As" not "Save a Copy").

5. Now all of the open windows are the new pdfs, not the original ai files.

6. Now I have to close each window. For some reason Illustrator asks me if I want to save each document when I tell it to close window, even though the file was just saved. I tell it to not save and everything seems to be fine.

7. Reopen all the files I just saved as high res pdfs.

8. Repeat the entire process except I run the script specifically designed for the low res pdfs.

 

What I would like to do is to combine these two processes so that there will be one script that saves both pdfs. From what I understand, the script can't support "Save A Copy" so the workflow would go as follows...

 

1. Open all files I wish to save as pdfs

2. Select single script to save files as both high res and low res pdfs

3. Illustrator asks me to choose a destination.

4. Illustrator saves each file as a High Res PDF and adds the the "_HR" suffix.

5. Illustrator then re-saves the open windows as a Low Res PDF and replaces the "_HR" suffix with "_LR".

 

Here is the code for the High Res script, The Low Res script is pretty much the same except for a different preset name and different suffix. Any pointer that anyone could give me would be most appreciated. I am pretty much a noob to this stuff so please keep that in mind.

 

Thanks!

Mike

 

---------------------------CODE----------------------------

 

/** Saves every document open in Illustrator

  as a PDF file in a user specified folder.

*/

 

 

// Main Code [Execution of script begins here]

 

 

try {

  // uncomment to suppress Illustrator warning dialogs

  // app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

 

 

  if (app.documents.length > 0 ) {

 

 

  // Get the folder to save the files into

  var destFolder = null;

  destFolder = Folder.selectDialog( 'Select folder for PDF files.', '~' );

 

 

  if (destFolder != null) {

  var options, i, sourceDoc, targetFile;

 

  // Get the PDF options to be used

  options = this.getOptions();

  // You can tune these by changing the code in the getOptions() function.

 

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

  sourceDoc = app.documents[i]; // returns the document object

 

  // Get the file to save the document as pdf into

  targetFile = this.getTargetFile(sourceDoc.name, '.pdf', destFolder);

 

  // Save as pdf

  sourceDoc.saveAs( targetFile, options );

  }

  alert( 'Documents saved as PDF' );

  }

  }

  else{

  throw new Error('There are no document open!');

  }

}

catch(e) {

  alert( e.message, "Script Alert", true);

}

 

 

/** Returns the options to be used for the generated files. --------------------CHANGE PDF PRESET BELOW, var NamePreset = ----------------

  @return PDFSaveOptions object

*/

function getOptions()

{var NamePreset = 'Proof High Res PDF';

  // Create the required options object

  var options = new PDFSaveOptions();

     options.pDFPreset="High Res PDF";

  // See PDFSaveOptions in the JavaScript Reference for available options

 

  // Set the options you want below:

 

 

  // For example, uncomment to set the compatibility of the generated pdf to Acrobat 7 (PDF 1.6)

  // options.compatibility = PDFCompatibility.ACROBAT7;

 

  // For example, uncomment to view the pdfs in Acrobat after conversion

  // options.viewAfterSaving = true;

 

  return options;

}

 

 

/** Returns the file to save or export the document into.----------------CHANGE FILE SUFFIX ON LINE BELOW, var newName = ------------------

  @param docName the name of the document

  @param ext the extension the file extension to be applied

  @param destFolder the output folder

  @return File object

*/

function getTargetFile(docName, ext, destFolder) {

  var newName = "_HR";

 

 

  // if name has no dot (and hence no extension),

  // just append the extension

  if (docName.indexOf('.') < 0) {

  newName = docName + ext;

  } else {

  var dot = docName.lastIndexOf('.');

  newName = docName.substring(0, dot)+newName;

  newName += ext;

  }

 

  // Create the file object to save to

  var myFile = new File( destFolder + '/' + newName );

 

  // Preflight access rights

  if (myFile.open("w")) {

  myFile.close();

  }

  else {

  throw new Error('Access is denied');

  }

  return myFile;

}

How to embed multiple images

$
0
0

Hello!

 

I have been tying to figure out how I could easily embed multiple linked images easily. I have some 1000 .svg  images which have about 1-7 .tif images linked in to them. I now need to get those links embedded and becouse of the amount of images I'm hoping to make an action out of it. I have a script to embed single image in .svg but haven't have luck with multiple embeddings.

 

Any ideas?

Illustrator Script - Export to PNG with options.

$
0
0

Hi everyone.

 

I would like some help on this script I currently have if anyone is able to.

 

What the script does - Exports multiple layers into single PNG images. Script is made with combination of scripts I've found over the net, and Actions I've composed.

 

What my problem is - PNG images are exported in low quality.

 

Basically, every image exported via this script is working fine, however the quality that it is exported into is much lower than that as you would export it manually via "File Export."

 

Can you help me with -the scripting code needed to implement so that the export quality is the same as you would do it manually?



Thank you for taking the time on this, I really appreciate any help and feed back.



-Arddy.


Resource - An extract of the code used to export is just below. This is the last part of my script and as I've said, I don't own this particular part it is something I found over the web.

 

   run_export: function() {

 

 

  var num_exported = 0;

  var options;

 

  if ( this.format =='PNG 8' ) {

     options = new ExportOptionsPNG8();

     options.antiAliasing = true;

     options.transparency = this.transparency;

     options.artBoardClipping = true;

     options.horizontalScale = this.scaling;

     options.verticalScale = this.scaling;   

           

  } else if ( this.format == 'PNG 24' ) {

     options = new ExportOptionsPNG24();

     options.antiAliasing = true;

     options.transparency = this.transparency;

     options.artBoardClipping = true;

     options.horizontalScale = this.scaling;

     options.verticalScale = this.scaling;   

    

  } else if ( this.format == 'PDF' ) {

            options = new PDFSaveOptions();

            options.compatibility = PDFCompatibility.ACROBAT5;

            options.generateThumbnails = true;

            options.preserveEditability = false;

    

  } else if ( this.format == 'JPG' ) {

     options = new ExportOptionsJPEG();

     options.antiAliasing = true;

     options.artBoardClipping = true;

     options.horizontalScale = this.scaling;

     options.verticalScale = this.scaling;   

    

  } else if ( this.format == 'EPS' ) {

            options = new EPSSaveOptions();

            options.embedLinkedFiles = true;

            options.includeDocumentThumbnails = true;

     options.saveMultipleArtboards = true;

  }

    

  var starting_artboard = 0;

  var num_artboards =  aDoc.artboards.length;

 

  if ( this.export_code == 'layers' ) {

     starting_artboard = aDoc.artboards.getActiveArtboardIndex();

     num_artboards = starting_artboard + 1;

  }

 

  for (var i = starting_artboard; i < num_artboards; i++ ) {

    

            var artboardName = aDoc.artboards[i].name;

            starting_artboard = aDoc.artboards.setActiveArtboardIndex(i);

    

            // Process this artbarod if we're exporting only a single one (layers mode) or if it doesn't have generic name or minus

            if ( this.export_code == 'layers' || ! ( artboardName.match(  /^artboard/i ) || artboardName.match( /^\-/ ) )) {

 

  // if exporting artboard by artboard, export layers as is

  if ( this.export_code == 'artboards' ) {

                   

     var base_filename = this.base_path + "/" + this.prefix + artboardName + this.suffix

 

 

     if ( this.format.match( /^PNG/ )) {               

  var destFile = new File( base_filename + '.png' );  

  var export_type = this.format == 'PNG 8' ? ExportType.PNG8 : ExportType.PNG24;

  aDoc.exportFile(destFile, export_type , options);

 

             } else if ( this.format.match( /^JPG/ )) {

                 var destFile = new File( base_filename + '.jpg' );  

                 var export_type = ExportType.JPEG;

                 aDoc.exportFile(destFile, export_type , options);

 

             } else if ( this.format.match( /^EPS/ )) {

 

 

  // dumb. specify a filename, saveAs saves as something else

  // so after we save it, we have to rename it to what we want.

  var eps_real_filename = base_filename + '_' + artboardName + '.eps'

 

                 var destFile = new File( base_filename + '.eps' );  

                 options.artboardRange = (i+1).toString();

                 aDoc.saveAs( destFile, options );

 

  var epsFile = new File ( eps_real_filename );

  if ( epsFile.exists ) {

     epsFile.copy( base_filename + '.eps'  );

                            epsFile.remove();

  }

 

     } else if ( this.format.match( /^PDF/ )) {

  var destFile = new File( base_filename + '.pdf' );  

  options.artboardRange = (i+1).toString();

  aDoc.saveAs( destFile, options )

     }      

                   

     // export layers as individual files

  } else if ( this.export_code == 'layers' || this.export_code = 'both' ) {

    

     for ( var j=0; j < aDoc.layers.length; j++ ) {

 

  this.hide_all_layers();

 

  var layer = aDoc.layers[j];

  var lyr_name = layer.name;

 

  if ( ! ( lyr_name.match( /^\+/ ) || lyr_name.match( /nyt_exporter_info/ ) || lyr_name.match( /^\-/) || lyr_name.match( /^Layer / ) )) {

    

     var base_filename;

    

     if ( this.export_code == 'layers' ) {

  base_filename = this.base_path + "/" + this.prefix + lyr_name + this.suffix

 

     } else if ( this.export_code == 'both' ) {

  base_filename = this.base_path + "/" + this.prefix + artboardName + '-' + lyr_name + this.suffix

 

 

     }

    

     layer.visible = true;

    

     if ( this.format.match( /^PNG/ )) {

  var destFile = new File( base_filename + '.png' );  

  var export_type = this.format == 'PNG 8' ? ExportType.PNG8 : ExportType.PNG24;

  aDoc.exportFile(destFile, export_type , options);

 

     } else if ( this.format.match( /^JPG/ )) {

  var destFile = new File( base_filename + '.jpg' );  

  var export_type = ExportType.JPEG;

  aDoc.exportFile(destFile, export_type , options);

 

     } else if ( this.format.match( /^EPS/ )) {

 

  var eps_real_filename = base_filename + '_' + artboardName + '.eps'

 

  var destFile = new File( base_filename + '.eps' );  

  options.artboardRange = (i+1).toString();

  aDoc.saveAs( destFile, options )

 

  var epsFile = new File ( eps_real_filename );

  if ( epsFile.exists ) {

     epsFile.copy( base_filename + '.eps'  );

     epsFile.remove();

    

  }

 

 

     } else if ( this.format.match( /^PDF/ )) {

  var destFile = new File( base_filename + '.pdf' );  

  options.artboardRange = (i+1).toString();

  aDoc.saveAs( destFile, options )

     }

    

     num_exported++;

    

     this.dlg.progLabel.text = 'Exported ' + num_exported + ' of ' + this.num_to_export;

     this.dlg.progBar.value = num_exported / this.num_to_export * 100;

    

     this.dlg.update();       

  }

 

     }

  }

     }

        }  

 

  this.prefs_xml.nyt_base_path    = this.base_path;

  this.prefs_xml.nyt_scaling      = this.scaling;

  this.prefs_xml.nyt_prefix       = this.prefix;

  this.prefs_xml.nyt_suffix       = this.suffix;

  this.prefs_xml.nyt_transparency = this.transparency;

  this.prefs_xml.nyt_format       = this.format;

  this.prefs_xml.nyt_export_code  = this.export_code;

   

  this.png_info_lyr.textFrames[0].contents = this.prefs_xml.toXMLString();

  this.dlg.close();

 

 

  //end run_export

    },

   

    hide_all_layers: function() {

  var export_count = 0;

 

  var n = aDoc.layers.length;

 

  for(var i=0; i<n; ++i) {

    

     layer = aDoc.layers[i];

    

     lyr_name = layer.name;

    

     // any layers that start with + are always turned on

     if ( lyr_name.match( /^\+/ ) ) {

  layer.visible = true;

 

     // any layers that start with -, have default layer name, or named "nyt_exporter_info" are skipped

     } else if ( lyr_name.match( /nyt_exporter_info/ ) || lyr_name.match( /^Layer /) || lyr_name.match( /^\-/ ) ){

  layer.visible = false;

 

     // everything else we should export

     } else {

  layer.visible = false;

  export_count++;

     }

  }

  return export_count;

    },

   

    get_num_layers_to_export: function() {

 

 

  var num_to_export = 0;

  var num_layers = aDoc.layers.length;

 

  for(var i=0; i<num_layers; ++i) {

    

     var layer = aDoc.layers[i];     

     var lyr_name = layer.name;

    

     // any layers that start with + are always turned on

     if ( lyr_name.match( /^\+/ ) ) {

 

     } else if ( lyr_name.match( /nyt_exporter_info/ ) || lyr_name.match( /^Layer /) || lyr_name.match( /^\-/ ) ){

 

     } else {

  num_to_export++;

     }

  }

 

  return num_to_export;

    },

   

    get_num_artboards_to_export: function() {

 

  var num_artboards = aDoc.artboards.length;

  var num_to_export = 0;

 

  for (var i = 0; i < num_artboards; i++ ) {

           

            var artboardName = aDoc.artboards[i].name;

            if ( ! ( artboardName.match(  /^artboard/i ) || artboardName.match( /^\-/ ) )){

                num_to_export++;

            }

  }

 

  return num_to_export;

 

    },

   

   

    show_all_layers: function() {

  var n = aDoc.layers.length;

  for(var i=0; i<n; ++i) {

     layer = aDoc.layers[i];

     layer.visible = true;

  }

    },

   

};

 

 

 

 

 

 

nyt_png_exporter.init();

How to log the ExtendScript Tool Kit console prints to a Text File

$
0
0

Hi Chaps,

 

I want to put prints in my whole Script and take the logs of the script.

To do this I need to log the entire console output to a Text file.


Can somebody please tell me how to write the console output to a log file?

Looking for "Replace with Symbol" script

$
0
0

So I am trying to replace gps points with a symbol I have created. I have found blogs referencing a script that can replace selected items with symbols saved in the symbols panel, but I can't seem to find the actual script! If anyone knows where I can find JET_ReplaceWithSymbol.jsx or any other script that can do the same function, it would be greatly appreciated!


Illustrator Crashing When Running Script

$
0
0

Hi!

 

So I have some Javascript I've compiled from sources and written myself to accomplish the task of duplicating an object across and down a page, along with adding a few elements at the end.

 

I must say it works pretty well and correctly, and I know this because it does so with SIMPLE vector artwork.  Anything beyond a solid fill, single color background and Illustrator crashes.

 

I've tried this on numerous machines, from the ancient to the cutting-edge, CS5 to CC 2017, and the result is always the same....CRASH!

 

Can anyone help me in figuring out the cause of failure?  Is it, perhaps, that I am trying to do too much with Javascript, or that my handle on the language is poor and inefficient?

 

Any help would be appreciated.

 

Code:

 

########################################################################################## ###########################################

 

//Variables established / The script will proceed if something is selected...

 

 

if (app.selection[0] != null) {

 

 

  var myDoc = app.activeDocument,

  selectedArt = myDoc.selection[0],

  xclone = 4, // set number across

         yclone = 6, // set number down

  horOffset = 162,  // set horizontal offset (pixels)

  verOffset = -162,  // set vertical offset (pixels)

  myDuplicate,

  i = 0

         j = 0

        

 

 

//Duplicates the selection along the x axis

 

 

  for (i;i < xclone;i++){

        if (i === xclone) { break; }

  myDuplicate = selectedArt.duplicate();

  myDuplicate.position = [selectedArt.position[0] + horOffset * (i + 1), selectedArt.position[1] + verOffset * (0)];

           

  }

 

 

//Groups all objects in the active document

 

 

     for ( h = 0; h < myDoc.pageItems.length; h++ ) {

            myDoc.pageItems[h].selected = true;

        }

        var docSelection = new Array;

        docSelection = app.activeDocument.selection;

  

        var Group1 = app.activeDocument.groupItems.add();

 

          if (docSelection.length > 0) {

               for (h = 0; h < docSelection.length; h++) {

                    docSelection[h].moveToEnd(Group1);

               }

          }

 

//Duplicates the selection (Group1) along the y axis

 

    for (j;j < yclone;j++){

        if (j === yclone) { break; }

  myDuplicate = Group1.duplicate();

  myDuplicate.position = [Group1.position[0] + horOffset * (0), Group1.position[1] + verOffset * (j + 1)];

  }

 

 

//Groups all objects in the active document

 

 

     for ( h = 0; h < myDoc.pageItems.length; h++ ) {

            myDoc.pageItems[h].selected = true;

        }

        var docSelection = new Array;

        docSelection = app.activeDocument.selection;

  

        var Group2 = app.activeDocument.groupItems.add();

 

          if (docSelection.length > 0) {

               for (h = 0; h < docSelection.length; h++) {

                    docSelection[h].moveToEnd(Group2);

               }

          }

 

//...Otherwise an exception is thrown

 

  }

else {

  alert("You must have an object selected.");

  }

 

 

{

   

//Resize Artboard [? , Height , Width , ?] (pixels)

 

app.activeDocument.artboards[0].artboardRect = [0,1134,871.2,0];

 

//Aligns selection (Group2) to artboard and deselects all

 

 

    {

    var myDoc = app.activeDocument; 

        app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM; 

    var abIdx = myDoc.artboards.getActiveArtboardIndex(); 

    var actAbBds = myDoc.artboards[abIdx].artboardRect; 

    var obj2move = Group2; 

        obj2move.position = new Array ((actAbBds[2]-actAbBds[0])/2 - obj2move.width/2, (actAbBds[3]-actAbBds[1])/2  + obj2move.height/2);

        app.selection = null;

    }

 

//Creates named paths to size and specifies a CMYK 100% Black fill [? ,  ? , Width , Height] (pixels)

 

    {

    var laserLine = app.activeDocument.pathItems.rectangle(0,0,9,1134);

        laserLine.name = "laserLine";

    var eyeMark = app.activeDocument.pathItems.rectangle(0,0,14.4,9);

        eyeMark.position = [856.8,-1125];   //[X,Y] (pixels)

        eyeMark.name = "eyeMark";

    var k = new CMYKColor;

        k.cyan= 0;

        k.magenta = 0; 

        k.yellow = 0;

        k.black = 100;

 

        laserLine.fillColor = k;

        eyeMark.fillColor = k;       

        }

}       

 

 

{

   

//Variables established / selects eyeMark path and duplicates along the y axis    

       

    verOffset = 162, // set vertical offset (pixels)

    yclone = 6, // set number up (offset is + now)

    myDuplicate,

    k = 0

       

    app.activeDocument.pageItems.getByName("eyeMark").selected = true;     

         

    for (k;k < yclone;k++){

        if (k === yclone) { break; }

  myDuplicate = eyeMark.duplicate();

  myDuplicate.position = [eyeMark.position[0] + horOffset * (0), eyeMark.position[1] + verOffset * (k + 1)];

  }

 

}

 

########################################################################################## ###########################################

Illustrator Scripting Panel

$
0
0

Just thought I'd share an extension I've been tinkering with:

 

GitHub - majman/adobe-scripts-panel: Scripting Panel for Adobe Illustrator

 

It's a pretty simple panel that allows you to try snippets of code in the editor, list and run saved scripts from your local files, or even load and run scripts from the web.

 

Hope somebody finds it helpful. Feel free to fork the repo and send pull requests.

 

-Marshall

Batching In Illustrator??

$
0
0

In PhotoShop CS3, you can select File/Automate/Batch, and run an Action on an entire folder.  I don't see that option in Illustrator CS3?  Is there a way to run an action on an entire folder?

 

I'm attempting to save many EPS images as PNG images, and would really like to retain "vector attributes" - is any of this possible???

 

Thanks for any help.

Duplicate a layer without changing the name (without "... - copy"

$
0
0

Hello !

 

 

I would like to know if there is a parameter in order to : when you duplicate a layer, the name of the layer don't change ?

For example :

I want to duplicate the layer "My layer". But, I don't want that my new layer is called "My layer - copy".

 

 

Is-it possible ?

 

 

Thank you for your answer

Retrieve whats in the clipboard possible?

$
0
0

Is it possible to retrieve whats in the clipboard through a script?

If so how?

Miximize window by script

script to align selected objects to artboard

$
0
0

Hello, I was wondering if anyone had a simple solution to aligning selected items to the artboard. I was going to create an action but then realized it would be more convenient for me to include it in my script file....I have a script to align objects with each other but they dont align to the artboard. Any suggestions?


Illustrator Script - Export to PNG with options.

$
0
0

Hi everyone.

 

I would like some help on this script I currently have if anyone is able to.

 

What the script does - Exports multiple layers into single PNG images. Script is made with combination of scripts I've found over the net, and Actions I've composed.

 

What my problem is - PNG images are exported in low quality.

 

Basically, every image exported via this script is working fine, however the quality that it is exported into is much lower than that as you would export it manually via "File Export."

 

Can you help me with -the scripting code needed to implement so that the export quality is the same as you would do it manually?



Thank you for taking the time on this, I really appreciate any help and feed back.



-Arddy.


Resource - An extract of the code used to export is just below. This is the last part of my script and as I've said, I don't own this particular part it is something I found over the web.

 

   run_export: function() {

 

 

  var num_exported = 0;

  var options;

 

  if ( this.format =='PNG 8' ) {

     options = new ExportOptionsPNG8();

     options.antiAliasing = true;

     options.transparency = this.transparency;

     options.artBoardClipping = true;

     options.horizontalScale = this.scaling;

     options.verticalScale = this.scaling;   

           

  } else if ( this.format == 'PNG 24' ) {

     options = new ExportOptionsPNG24();

     options.antiAliasing = true;

     options.transparency = this.transparency;

     options.artBoardClipping = true;

     options.horizontalScale = this.scaling;

     options.verticalScale = this.scaling;   

    

  } else if ( this.format == 'PDF' ) {

            options = new PDFSaveOptions();

            options.compatibility = PDFCompatibility.ACROBAT5;

            options.generateThumbnails = true;

            options.preserveEditability = false;

    

  } else if ( this.format == 'JPG' ) {

     options = new ExportOptionsJPEG();

     options.antiAliasing = true;

     options.artBoardClipping = true;

     options.horizontalScale = this.scaling;

     options.verticalScale = this.scaling;   

    

  } else if ( this.format == 'EPS' ) {

            options = new EPSSaveOptions();

            options.embedLinkedFiles = true;

            options.includeDocumentThumbnails = true;

     options.saveMultipleArtboards = true;

  }

    

  var starting_artboard = 0;

  var num_artboards =  aDoc.artboards.length;

 

  if ( this.export_code == 'layers' ) {

     starting_artboard = aDoc.artboards.getActiveArtboardIndex();

     num_artboards = starting_artboard + 1;

  }

 

  for (var i = starting_artboard; i < num_artboards; i++ ) {

    

            var artboardName = aDoc.artboards[i].name;

            starting_artboard = aDoc.artboards.setActiveArtboardIndex(i);

    

            // Process this artbarod if we're exporting only a single one (layers mode) or if it doesn't have generic name or minus

            if ( this.export_code == 'layers' || ! ( artboardName.match(  /^artboard/i ) || artboardName.match( /^\-/ ) )) {

 

  // if exporting artboard by artboard, export layers as is

  if ( this.export_code == 'artboards' ) {

                   

     var base_filename = this.base_path + "/" + this.prefix + artboardName + this.suffix

 

 

     if ( this.format.match( /^PNG/ )) {               

  var destFile = new File( base_filename + '.png' );  

  var export_type = this.format == 'PNG 8' ? ExportType.PNG8 : ExportType.PNG24;

  aDoc.exportFile(destFile, export_type , options);

 

             } else if ( this.format.match( /^JPG/ )) {

                 var destFile = new File( base_filename + '.jpg' );  

                 var export_type = ExportType.JPEG;

                 aDoc.exportFile(destFile, export_type , options);

 

             } else if ( this.format.match( /^EPS/ )) {

 

 

  // dumb. specify a filename, saveAs saves as something else

  // so after we save it, we have to rename it to what we want.

  var eps_real_filename = base_filename + '_' + artboardName + '.eps'

 

                 var destFile = new File( base_filename + '.eps' );  

                 options.artboardRange = (i+1).toString();

                 aDoc.saveAs( destFile, options );

 

  var epsFile = new File ( eps_real_filename );

  if ( epsFile.exists ) {

     epsFile.copy( base_filename + '.eps'  );

                            epsFile.remove();

  }

 

     } else if ( this.format.match( /^PDF/ )) {

  var destFile = new File( base_filename + '.pdf' );  

  options.artboardRange = (i+1).toString();

  aDoc.saveAs( destFile, options )

     }      

                   

     // export layers as individual files

  } else if ( this.export_code == 'layers' || this.export_code = 'both' ) {

    

     for ( var j=0; j < aDoc.layers.length; j++ ) {

 

  this.hide_all_layers();

 

  var layer = aDoc.layers[j];

  var lyr_name = layer.name;

 

  if ( ! ( lyr_name.match( /^\+/ ) || lyr_name.match( /nyt_exporter_info/ ) || lyr_name.match( /^\-/) || lyr_name.match( /^Layer / ) )) {

    

     var base_filename;

    

     if ( this.export_code == 'layers' ) {

  base_filename = this.base_path + "/" + this.prefix + lyr_name + this.suffix

 

     } else if ( this.export_code == 'both' ) {

  base_filename = this.base_path + "/" + this.prefix + artboardName + '-' + lyr_name + this.suffix

 

 

     }

    

     layer.visible = true;

    

     if ( this.format.match( /^PNG/ )) {

  var destFile = new File( base_filename + '.png' );  

  var export_type = this.format == 'PNG 8' ? ExportType.PNG8 : ExportType.PNG24;

  aDoc.exportFile(destFile, export_type , options);

 

     } else if ( this.format.match( /^JPG/ )) {

  var destFile = new File( base_filename + '.jpg' );  

  var export_type = ExportType.JPEG;

  aDoc.exportFile(destFile, export_type , options);

 

     } else if ( this.format.match( /^EPS/ )) {

 

  var eps_real_filename = base_filename + '_' + artboardName + '.eps'

 

  var destFile = new File( base_filename + '.eps' );  

  options.artboardRange = (i+1).toString();

  aDoc.saveAs( destFile, options )

 

  var epsFile = new File ( eps_real_filename );

  if ( epsFile.exists ) {

     epsFile.copy( base_filename + '.eps'  );

     epsFile.remove();

    

  }

 

 

     } else if ( this.format.match( /^PDF/ )) {

  var destFile = new File( base_filename + '.pdf' );  

  options.artboardRange = (i+1).toString();

  aDoc.saveAs( destFile, options )

     }

    

     num_exported++;

    

     this.dlg.progLabel.text = 'Exported ' + num_exported + ' of ' + this.num_to_export;

     this.dlg.progBar.value = num_exported / this.num_to_export * 100;

    

     this.dlg.update();       

  }

 

     }

  }

     }

        }  

 

  this.prefs_xml.nyt_base_path    = this.base_path;

  this.prefs_xml.nyt_scaling      = this.scaling;

  this.prefs_xml.nyt_prefix       = this.prefix;

  this.prefs_xml.nyt_suffix       = this.suffix;

  this.prefs_xml.nyt_transparency = this.transparency;

  this.prefs_xml.nyt_format       = this.format;

  this.prefs_xml.nyt_export_code  = this.export_code;

   

  this.png_info_lyr.textFrames[0].contents = this.prefs_xml.toXMLString();

  this.dlg.close();

 

 

  //end run_export

    },

   

    hide_all_layers: function() {

  var export_count = 0;

 

  var n = aDoc.layers.length;

 

  for(var i=0; i<n; ++i) {

    

     layer = aDoc.layers[i];

    

     lyr_name = layer.name;

    

     // any layers that start with + are always turned on

     if ( lyr_name.match( /^\+/ ) ) {

  layer.visible = true;

 

     // any layers that start with -, have default layer name, or named "nyt_exporter_info" are skipped

     } else if ( lyr_name.match( /nyt_exporter_info/ ) || lyr_name.match( /^Layer /) || lyr_name.match( /^\-/ ) ){

  layer.visible = false;

 

     // everything else we should export

     } else {

  layer.visible = false;

  export_count++;

     }

  }

  return export_count;

    },

   

    get_num_layers_to_export: function() {

 

 

  var num_to_export = 0;

  var num_layers = aDoc.layers.length;

 

  for(var i=0; i<num_layers; ++i) {

    

     var layer = aDoc.layers[i];     

     var lyr_name = layer.name;

    

     // any layers that start with + are always turned on

     if ( lyr_name.match( /^\+/ ) ) {

 

     } else if ( lyr_name.match( /nyt_exporter_info/ ) || lyr_name.match( /^Layer /) || lyr_name.match( /^\-/ ) ){

 

     } else {

  num_to_export++;

     }

  }

 

  return num_to_export;

    },

   

    get_num_artboards_to_export: function() {

 

  var num_artboards = aDoc.artboards.length;

  var num_to_export = 0;

 

  for (var i = 0; i < num_artboards; i++ ) {

           

            var artboardName = aDoc.artboards[i].name;

            if ( ! ( artboardName.match(  /^artboard/i ) || artboardName.match( /^\-/ ) )){

                num_to_export++;

            }

  }

 

  return num_to_export;

 

    },

   

   

    show_all_layers: function() {

  var n = aDoc.layers.length;

  for(var i=0; i<n; ++i) {

     layer = aDoc.layers[i];

     layer.visible = true;

  }

    },

   

};

 

 

 

 

 

 

nyt_png_exporter.init();

Delete/Remove/Overwrite files/folders while saving

$
0
0

Hello again.

 

I am finishing up a simple script similar to one you've probably seen and more than likely used before (multiexporter.jsx by Tom Byrne). My production department has requested that we give them a single PDF per artboard in the document with specific export settings and a proper file-name (based on the name of the artboard).

 

i've written a loop to save out each artboard with all the right settings.. but now i'm running into the problem of duplicates. It's very likely that I will have many duplicate artboard names, but they all need to be saved. By default, the files are overwritten by the subsequent save function. I got past that by adding a sort of sequence number to the end of the filename if a duplicate is found.

 

The problem now, is that I would like the script to run correctly regardless of whether the destination folder exists or not. For example, I've already run the script and saved my .ai file and all the PDFs. Now i realize that i needed to make a change to the file and re-save (via the script) and overwrite the files i saved there the first time. Unfortunately, because of the sequence numbers i talked about above, i get all the old files as well as all the new files in the folder.

 

My first thought was to delete the existing destination folder and re-create it. However, it looks like Javascript cannot do that. Will i just have to tell my artists they must manually delete their folder before they re-run the script? or is there a way to overwrite the folder while still maintaining the sequencing for duplicate files inside the folder??

 

Here's the code:

 

#target Illustrator


//Script name: Save Document and Extract PDFs
//Author: William Dowling
//Creation Date: 10/15/15
/*
    Saves active document to user's desktop in dated folder with order number as filename.    Saves each artboard as a PDF with artboard name as filename.
*/


function container(){
    var docRef = app.activeDocument;    var layers = docRef.layers;    var aB = docRef.artboards;    var dest = findDest();    var date = getDate();        function findDest(){        var dest = new Folder("~/Desktop" + "/Today's Orders");        return dest.fsName;    }        function getDate(){            var today = new Date();            var dd = today.getDate();            var mm = today.getMonth()+1;            var yyyy = today.getYear();            var yy = yyyy-100;            if(dd<10) {                dd='0'+dd            }             if(mm<10) {                mm='0'+mm            }             return mm+'.'+dd+'.'+yy;        }        dest = "/Volumes/Macintosh HD" + dest + " " + date;    if(!dest.exists){        var newFolder = new Folder(dest);        newFolder.create();    }    if(docRef.name.substring(0,2) == "Un"){        var oN = prompt("Enter Order Number", "1234567");        var fileName = oN;    }    else{        var fileName = docRef.name;    }    var saveFile = new File(dest + "/" + fileName);    if(saveFile.exists){        if(!confirm("This File already exists.. Do you want to overwrite?", false, "Overwrite file?")){            return;        }    }    docRef.saveAs(saveFile);    var pdfdest = dest + "/" + fileName.substring(0,fileName.indexOf(".ai")) + "_PDFs";    var pdfFolder = new Folder(pdfdest);    if(!pdfFolder.exists){        pdfFolder.create();    }    else if(pdfFolder.exists){        if(!confirm("The PDFs folder for this order already exists.. Do you want to overwrite?", false, "Overwrite PDFs Folder?")){            return;        }        else{             //pdfFolder.Delete(); //within this else statement, i'd like to remove the folder or it's contents and start with a fresh folder            pdfFolder = new Folder(pdfdest);            pdfFolder.create();        }    }        //loop artboards to save individual PDFs        var pdfSaveOpts = new PDFSaveOptions();    pdfSaveOpts.preserveEditability = false;    pdfSaveOpts.viewAfterSaving = false;    var seq = 1;    for(var a=0;a<aB.length;a++){        var range = (a+1).toString();        pdfSaveOpts.artboardRange = range;        var pdfFile = new File(pdfdest + "/" + aB[a].name);        var thisPDF = new File(pdfFile + ".pdf");        if(thisPDF.exists){            thisPDF = new File(pdfFile + " " + seq.toString());            docRef.saveAs(thisPDF, pdfSaveOpts);            seq++;        }        else{            docRef.saveAs(pdfFile, pdfSaveOpts);        }    }
}
container();

Adobe Illustrator UDP communication

$
0
0

Possibility.png

In Adobe illustrator is there any possibility to access it layers and children in Qt?

 

OR

 

is there any option to communicate between an extended javascript via UDP to a Qt Application?

 

Cheers

Nidhin

How can I batch a huge bunch of wmf to ai in multiple subfolders?

$
0
0

Hi,

 

I have a couple of thousand old cliparts in .wmf format that I have to convert to .ai.  What I need to do is simply open the .wmf, store it as .ai in exactly the same location.

 

Actions didn´t work because the files are in mutliple folders and subfolders. "Actions" keeped saving all the ai-files in the same folder. Which is kinda weird since this doesn´t happen when using the same action in PS.

 

Sure, there are some quality issues with converting wmf to ai - but for what we´re plannning the quality is sufficient.

 

CarlosCantos script at http://forums.adobe.com/message/5378444#5378444  looked like the thing to do. Loaded it in apple script,  patched the lines to open .wmf  and saved it in the Illustrator script folder, but all I got was a bunch of error messages, so I´m pretty clueless :-/ guess I´m not a script guy...

 

Any help is greatly appreciated

 

HF

Illustrator Scripting Panel

$
0
0

Just thought I'd share an extension I've been tinkering with:

 

GitHub - majman/adobe-scripts-panel: Scripting Panel for Adobe Illustrator

 

It's a pretty simple panel that allows you to try snippets of code in the editor, list and run saved scripts from your local files, or even load and run scripts from the web.

 

Hope somebody finds it helpful. Feel free to fork the repo and send pull requests.

 

-Marshall

Viewing all 12845 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>