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

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();


Export file as a DXF

$
0
0

My script is working nice until I try to export my document. I am trying to export my document as a DXF file.  Using the Illustrator CS6 Scripting Reference I am using the TIFF export as a reference as there are no examples for exporting as a DXF (my luck!).  This is what I have in VBscript.  With this script I get the following error on the second to last line:

 

"Illegal argument - argument 2 - Enumerated value expected"

 

As you can see I do have one: "0" so I suspect the error lies elsewhere in the code?  I'll take a JavaScript example if you are not into VBscript since the two look very similar and I think I can adapt it.

 

Set App = CreateObject("Illustrator.Application")

Set FSO = CreateObject("Scripting.FileSystemObject")

 

Dim dest

dest = "S:\SOCAL\Section_32\Veg DXFs LC\SOCAL_CK67_pineLC"

 

Set DXFexport = CreateObject("Illustrator.ExportOptionsAutoCAD")

    If App.Documents.Count > 0 Then

        Set docRef = App.ActiveDocument

        Call docRef.Export (dest, 0, DXFexport)      ' 0 = aiDXF

    End If

Change spot color and move to specific layer

$
0
0

I am new with scripting in Illustrator but see a need to script some repetitive tasks.

I start with a document that has most art on Layer 15 colored with various spot colors

I need to select all strokes of a specific color, change it to another color and move it to a different sub layer.

 

Layer 15

     all art

Template layer

     Cut

     Bleed

     Score

 

Can someone please get me started with the commands? I picked up on others who were moving items to different layers, but not changing colors also.

Anti-aliasing Type Optimized/Art Optimized on PNG export

$
0
0

Hello there,

 

I'm modifying a javascript that makes an export of each layer contained in an Illustrator document and I want to specify the method used for anti-aliasing (either Type Optimized or Art Optimized). Similarly to the option under the "Image size" tab in the "Save for the Web" panel.

 

I didn't find any antiAliasingMethod property in the ExportOptionsPNG24 properties (only an antiAliasing property that accepts boolean). So I wonder if it is actually possible to do it through scripting?

 

Many thanks,

D

Setting the bleed in AI via Javascript

$
0
0

Hi All,

 

I'm writing a function to change the artboard size and add bleed depending on certain conditions.

I can't actually believe this is causing me trouble but here it is, I'm trying to set the bleed dimensions in AI document with Javascript. All I've found so far is setting up PDF export options or print options, but not the actual artboard Document Setup. I just want to be able to set bleed to a newly created document like in this window:

So similar to Indesign:

 

with(myDocument.documentPreferences){  documentBleedUniformSize = true;  documentBleedTopOffset = 7;  }

 

(CC2017)

Screenshot 2017-04-06 15.45.28.png

Convert .ai to .doc

$
0
0

Hi,

 

Can it be possible to convert .ai file into .doc file or any tool which will do this conversion.

 

Thanks,

Shail

Script: rename layers?

$
0
0

Hi, is there a quick way how to renumber or batch rename all layers in a file so they would be named in consequent numbers? Doesn't have to start from exact number, I was wondering if maybe there is some sort of script that would help me with that? Thanks Pavel

Selecting objects by fill color

$
0
0

Hi guys

Is possible to select objects by color in CMYK using JavaScript?

All I want to group several objects with the same fill color.

 

Many thanks for your time...

 

Please see the picture bellow...

 

2.jpg


Is there any way, so that I could place the cursor in a selected text using javascript in illustrator. [Locked – Duplicate thread]

Creating Multi-Page PDF from a Layerd Illustrator file (script)

$
0
0

Often times when designing a logo I create different versions and variable options on layers. This can result in several layers in one Illustrator file. Is there an easy way or an existing script that will allow me to (with one click) create a multi-page PDF consisting of all the layers within my .ai file? The current method is turning on each layer, performing a save-as (PDF), then turning off said layer and turning on the next layer and repeating the task and so-on-and-so-forth, etc … It becomes tedious and quite often I save over the previous version, forgetting to re-name it or forget to perform a save on a certain layer. Can anyone help with some advice? I have never written my own script before but am not opposed to trying, where do I begin?

Any help is appreciated.

How can I modify the "Save as PDF" script to avoid the save dialogue? [Locked – Duplicate post]

$
0
0

Okay, I found out how to modify the "Save as PDF" javascript supplied with Illustrator so that it renders the .pdf with my preferred .joboption (e.g. X3) - what I'm lacking and don't seem to be able to find out via google is how to suppres the save dialogue (asking me about the location where to save the file every time I invoke that script).

 

I'd like the script to save the PDF

 

- in exactly the same location as the .ai document

- overwrite any probably existing .pdf file with the same name without asking

 

Can anybody here tell me how to do this trick?

 

 

Thx. in advance!

 

 

 

[duplicate thread locked by moderator] --> How can I modify the "Save as PDF" script to avoid the save dialogue?

jsx script illustrator - replace items color with a corresponding swatch pattern

$
0
0

I am attempting to create a script to replace all the colors in a picture with a number pattern. I have created a script but it does not work as intended.

The picture is coloured with swatches and need to be replaced by a swatch with the same name but for a "." at the end, i.e. all items of colour Bh will need to be replaced with Bh. pattern.

 

 

doc = activeDocument,

swatches = doc.swatches,

items = doc.pathItems;

var correspondingSwatch;

 

for (var c = 0; c < swatches.length; c++) {

    correspondingSwatch = null

 

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

        if (swatches[i].name == swatches[c].name + "." ) correspondingSwatch = swatches[i];

    }

 

    if (correspondingSwatch != null) {

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

            if (items[i].fillColor == swatches[c].color) items[i].fillColor= correspondingSwatch.color;

        }

    }

}

 

 

The first and second for loop work as intended but the third for loop does not.

(items[i].fillColor == swatches[c].color) i want this to return true when the color of the item[i] is the same as the swatches[c] but it does not.

(items[i].fillColor  = correspondingSwatch.color) i want this to fill in the item with the correspondingSwatch pattern, not the color. However I do not know the syntax to use a swatches color to paint an item.

 

Thank you any one who gives this a read, i am familiar with programming but am just starting on adobe illustrator scripting.

If you could change the code and send it back that would be great, or even telling me what methods or variables to use.

A javascript for showing the name of used font.

$
0
0

Hi,
I need to show the name of font which is used in the active document. I am new in scripting. I don't get any clue for this.

 

 

 

doc = activeDocument;

texts = doc.textFrames;

count = texts.length;

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

    textRef = texts[i];

    textRef.selected = true

var f=textRef.Font ; 

alert(f);

 

Every-time, I am getting "undefined". Can Anyone give me what is wrong in this code? Thanks in advance.

Creating an action that uses Layers

$
0
0

Hello! I'm trying to create an action that involves layers turning on and off and copy/pasting to different layers but when I recorded the action it ignores all of the layer changes and pastes then images on top of each other in 1 layer. Any ideas?

 

More info: I have a file with 60+ small artboards that I'm creating icons on. Then I have 7 layers of different colors, so the art is exactly the same on each layer except it's a different color. So the reason I'm trying to make an action is to make it easier for when I make new icons I'd like to speed up the process.


I want my action to: copy the vector from layer 1, turn off layer 1, turn on layer 2, paste in place, change colors, and then do it all over again 6-7 times. Does that make sense? Hope someone has some ideas!

 

 

Thanks in advance!!

Problem loading an artboard to extension with multiple images

$
0
0

Hello guys,

i have a situation while laoding an artboard. This artboard consists of 4 images. while trying to load it into illustrator its working fine and while loading on to an extension only the first image is opening fine and all the remaining were breaking.

I have tried loading different artboards with multiple images. They worked fine.

That file which i am unable to load into extension was given by our client. I dont know whether there is a problem in that .ai file or what ever. This is the only file i am unable to load to extension.

Could come one please help me with this


How to add superscript 2 as text in textGroupItem with Javascript

$
0
0

Dear All,

 

I've been trying to add and remove certain pieces of text based on their font and whenever I need to add a certain piece of text back into it's original place again I need to insert a superscript 2 after this text.

This is the piece of code in which I add the text back in again:

 

if (textGroupItem.textRange.characterAttributes.textFont.toString().toLowerCase().match(regP attern)){

                textGroupItem.textRange.characters.removeAll()

                textGroupItem.textRange.characters.add(un + " - " + sm + "m" + "²")

}

This doens't give a superscript 2 but some kind of broken token as text.

 

So far i've also tried:

- translatePlaceholderText("c2b2")

- "2".sup()

-  <sup> 2</sup>

- textGroupItem.textRange.characterAttributes.baselineShift = height;  <-- height = 2 but this shifts the whole text item

 

 

How can you succesfully add a supercript 2 to a group of characters?

Ai Packaging Script

$
0
0

Ok.. I'm sure this has been posted before (already searched, didn't find however), but does a file packaging script exist for AI? (one that collects all linked images and fonts and places them in one place) This would be IMMENSELY helpful to me if anyone can post a link to one or even be willing to write it.

 

OS: W7

AI Version: CS5

 

Thanks in advance!

Drawing a rectangle of exact size of the artboard?

$
0
0

Has anybody written a JS script to to draw a rectangle on an active document which would be exact size as the document's artboard?

I find it very inaccurate and cumbersome trying to draw such rectangle by hand.

 

Please let me know where such JS code can be found. I have not done any Illustrator scripting beyond the "Hello world".

 

Thanks

franK

A javascript for showing the name of used font.

$
0
0

Hi,
I need to show the name of font which is used in the active document. I am new in scripting. I don't get any clue for this.

 

 

 

doc = activeDocument;

texts = doc.textFrames;

count = texts.length;

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

    textRef = texts[i];

    textRef.selected = true

var f=textRef.Font ; 

alert(f);

 

Every-time, I am getting "undefined". Can Anyone give me what is wrong in this code? Thanks in advance.

Selecting objects by fill color

$
0
0

Hi guys

Is possible to select objects by color in CMYK using JavaScript?

All I want to group several objects with the same fill color.

 

Many thanks for your time...

 

Please see the picture bellow...

 

2.jpg

Viewing all 12845 articles
Browse latest View live


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