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

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.


Getting *.ai files within subfolders

$
0
0

I'm sure this question has been asked before and I've searched, but I haven't been able to figure this out... mostly because I'm quite new to scripting.

 

I'm working from the included SaveDocsasPDF script to make my own and batch convert files into PDFs. It works fine, so long as all the AI files are in the one folder... but they're not. They're spread across about 20 different subfolders. It's okay if the output PDFs are all placed into the one export folder, but I'd like for the script to find the AI files within their subfolders.

 

If there's any other ways to make the code more efficient, that would be great, too. For example, I don't need it to ask for a type of Illustrator file... if it just automatically looked for "*.ai" files, that'd be fine... I couldn't figure that out on my own :/

 

Here's the current script:

 

// Main Code [Execution of script begins here]


// uncomment to suppress Illustrator warning dialogs
// app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;


var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pdfSaveOpts;


// Select the source folder.
sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to PDF', '~' );


// If a valid folder is selected
if ( sourceFolder != null )
{
  files = new Array();  fileType = prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' );  // Get all files matching the pattern  files = sourceFolder.getFiles( fileType );  if ( files.length > 0 )  {  // Get the destination to save the files  destFolder = Folder.selectDialog( 'Select the folder where you want to save the converted PDF files.', '~' );  for ( i = 0; i < files.length; i++ )  {  sourceDoc = app.open(files[i]); // returns the document object  // Call function getNewName to get the name and file to save the pdf  targetFile = getNewName();  // Call function getPDFOptions get the PDFSaveOptions for the files  pdfSaveOpts = getPDFOptions( );  // Save as pdf  sourceDoc.saveAs( targetFile, pdfSaveOpts );  sourceDoc.close();  }  alert( 'Files are saved as PDF in ' + destFolder );  }  else  {  alert( 'No matching files found' );  }
}


/*********************************************************


getNewName: Function to get the new file name. The primary
name is the same as the source file.


**********************************************************/


function getNewName()
{
  var ext, docName, newName, saveInFile, docName;  docName = sourceDoc.name;  ext = ' LR.pdf'; // new extension for pdf file  newName = "";  for ( var i = 0 ; docName[i] != "." ; i++ )  {  newName += docName[i];  }  newName += ext; // full pdf name of the file  // Create a file object to save the pdf  saveInFile = new File( destFolder + '/' + newName );  return saveInFile;
}


/*********************************************************


getPDFOptions: Function to set the PDF saving options of the
files using the PDFSaveOptions object.


**********************************************************/


function getPDFOptions()
{
  // Create the PDFSaveOptions object to set the PDF options  var pdfSaveOpts = new PDFSaveOptions();  // Setting PDFSaveOptions properties. Please see the JavaScript Reference  // for a description of these properties.  // Add more properties here if you like  pdfSaveOpts.pDFPreset = "North Atlantic - Lo-res"  return pdfSaveOpts;
}

 

Any help would be greatly appreciated!

Convert string (string of JSON) to JSON object?

$
0
0

**EDIT**

I finally figured out how to use #include instead of file.read();. This solves my immediate problem. However I am still curious as to whether it's possible to do what I'm asking for below, just in case there comes a situation where for whatever reason I cannot simply use #include. Thanks everyone. =)

**EDIT**

 

**EDIT 2**

Anyone know how to use #include for a file whose name is determined during script execution?

For example.. the variable orderNumber is generated by a prompt window (lets say the result is 1234567). the file i want to include will be named "1234567.js).

What I want to do is something like:

#include "~/Desktop/Info Folder/" + orderNumber + ".js"

(then I want to assign a variable to the result somehow, since it's simply an anonymous object at this point and i don't know how to access it's contents);

**EDIT 2**

 

Hey all. I have a (most likely really stupid) question about how to take a string that contains the JSON text and simply change it's type from "string" to "object"... I'm probably wording this very badly.

 

I'm fetching a .js file from my local network and setting a variable to the result of file.read();

 

The contents of the file is an anonymous object in JSON. However, when i use file.read(); the object is brought in as a string, like this:

 

'{"roster":[{"name":"Fink","number":"19","jerseySize":"XL","qty":"1","topId":"78531"},{thi s is the next player},{this is the next player}]}'

 

That is a massively simplified version of what i'm actually reading, but you get the point. I want to be able to bring that object into the script that I'm running and create new objects based on the pertinent information (in this case i only need the values for "name", "number", and "jerseySize").

 

So my question is this. how do i turn the above string of JSON into:

 

var roster = [

     {

     "name":"Fink",

     "number":"19",

     "jerseySize":"XL"},

     {

     next player

     },

     {

     next player

     }

]

 

???? A google search reveals the method JSON.parse(text). But that is not supported in ESTK.

Select an object in illustrator using extendscript

$
0
0

I have a drawn rectangle on an illustrator document. In the layers menu I have given it a specific path name (outerBox). I would like to select this item and return its particular properties eg height, width, colour etc. How would I do this.

 

Thanks

Bob

Illustrator CC Book Color vs Spot Color PANTONE+

$
0
0

Hi! Here's a question about a little detail regarding PANTONE+ spot colors.
I've got a script that makes PANTONE+ colors inside a document using the available scripting methods, which produce a spot color with the desired Lab color values, but when double-clicking and bringing up the swatch dialog it does not default to the grayed-out "Book Color" option in the Color Mode dropdown.

However, it does have the Book Color option in that dropdown and if it's selected and applied, the next time this swatch is double-clicked and dialog appears, the proper Book Color mode is selected and appropriate fields are grayed out.

 

My question is: considering the functions of spot colors in Illustrator, ink plating and appearance and anything else, does my script-made swatch bear any effect on the document that would make it in any way different than a regular document where the Book Color is shown as default in the swatch options dialog?

 

In Mordy Golding's explanation of Book Color mode for Pre-CS6 versions, he states that Book Colors came with hidden information which displays PANTONE-listed Lab values which relate to the Pre-CS6 CMYK-based PANTONE swatches. Now that we have PANTONE+, and Lab is the default base for the book swatches, I wonder if there is any other property that may not be considered by some function of the application if the swatch has the correct name and Lab values while not having the Book Color mode explicitly selected.

Also, if there's an undocumented property for setting the other Color Modes which can appear in this dropdown, that would also be useful information. Our current available options for SpotColorKind are just SPOTCMYK, SPOTLAB and SPOTRGB
Screen Shot 2015-10-04 at 6.57.46 PM.png

Lab-VS-Book.png

an Illustrator error occurred: 1346458189 ('PARM')

$
0
0

Hello everyone,

 

I am trying to open some documents in Illustrator CS4 by javascript, walk through all layers including sublayers, doing something (for now just reading the layernames and showing them at an alert), closing the document and continue with the next document in the given folder until all documents in that folder are done.

 

By doing so I found an error I never have seen so far and I cant figure out where it comes from exactly to get rid of it.

The Error an Illustrator error occurred: 1346458189 ('PARM') appears randomly when cycling through the layers of the document but only every second document, so I guess there might be something wrong with closing a document and realeasing all references but I could not figure out what.

 

Maybe someone got an idea on this problem? Posting my sourcecode (just a simple test-code) below.

 

 

#target illustrator

 

var sourceFolderPath = "/e/TestAI";

var destinationFolderPath = "/e/TestZielverzeichnis";

var fileNameDefinition = "*.ai";

var sourceFolder = new Folder(sourceFolderPath);

var destinationFolder = new Folder(destinationFolderPath);

 

runCheckTool();

 

function runCheckTool() {

var contentInput = sourceFolder.getFiles(fileNameDefinition);

var fileRef;

var docRef;

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

fileRef = null;

docRef = null;

try {

fileRef = new File(contentInput[i]);

docRef = open(fileRef);

} catch(e) {

alert("# 1: " + e);

}

 

try{

checkLayers(docRef.layers);

} catch(e) {

alert("# 2: " + i + " " + e);

}

 

try {

docRef.close(SaveOptions.DONOTSAVECHANGES);

alert("end file index: " + i);

} catch(e) {

alert("#3: " + e);

}

}

}

 

function checkLayers(layerRef) {

var countLayers = layerRef.length;

for (var j = countLayers - 1; j >= 0; j--) {

if(layerRef[j].layers.length > 0) {

checkLayers(layerRef[j].layers);

}

alert ("Layer: " + layerRef[j].name);

}

}

 

 

Screenshot001.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

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


Find overlapping text in text frame

$
0
0

I would like to count the number of characters of the frame, which will include overset, and compare it with the count for all the lines in the frame, which will exclude overset.

 

I know how to get the first one:   

     set number_of_chars tocount my_text

 

But I don't know how to get the second one

How add trim marks and bleed to PDF MultiExporter.jsx

$
0
0

I am using MultiExporter.jsx

 

An Illustrator script for exporting layers and/or artboards into separate files (PNG8 / PNG24 / EPS / PDF / SVG / JPG / …

 

I would like to add this options when saving multiple artboards to separate PDFs:

- trim marks

- bleed: always 3 mm or: use document bleed settings

 

I managed to add trim marks but it makes bleed bigger than the desired 3mm

 

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

            options = new PDFSaveOptions();

            options.compatibility = PDFCompatibility.ACROBAT5;

            options.generateThumbnails = true;

            options.preserveEditability = false;

            options.trimMarks = true;

 

Any ideas?

Thank you so much,

Script : Save Illustrator CC to CS6

$
0
0

Hello, I am really beginner in the use of scripts in illustrator so I try my luck here!

I'm looking for a batch action script that would save my Illustrator CC files to Illustrator CS6, with a suffix on the file name: "-CS6".This would give "date-name-version-CS6". How can I do this? Thank you for your answers !

Javascript: Spot Colors and Inks

$
0
0
Using CS3.

Can anyone explain why Illustrator's Javascript considers any Global color a Spot Color? To see what I mean, please follow these steps:

1. Download thisthis .zip archive. It contains a small script which simply presents an alert for each Swatch in the active document, showing the swatch's name and color (type).

2. New CMYK Document. Run the Action named Delete Unused Panel Items. You should end up with only these swatches: [None], [Registration], Black, White.

3. Run the GetDocumentSwatchesInfo script. You'll see that Illustrator's Javascript considers Black and White CMYKColor, and Registration a SpotColor. So far, so good.

4. Swatches Palette flyout menu: New Swatch. Define a new swatch of any color. Make it Process.

5. Run the GetDocumentSwatchesInfo script again. Black, White, and your new swatch are CMYKColor.

6. DoubleClick your new swatch. In the Swatch Options dialog, change it from Process to Spot Color.

7. Run the GetDocumentSwatchesInfo script again. Black, White are CMYKColor; your new swatch is Spot Color.

8. DoubleClick your new swatch again. Change it from Spot Color to Process. But this time, turn on the Global checkbox.

9. Run the GetDocumentSwatchesInfo script again. Your new swatch is shown to be consider a Spot Color, despite the fact it is process.

It seems that any process swatch that I turn on as Global is considered by AI's Javascript to be a Spot Color. If you do an alert that returns app.activeDocument.spots.length, you'll see that the number of Spots includes not just spot color swatches, but spot color swatches plus global swatches.

Is this right? Looking through AICS3 Javascript Reference, I can't find anything to justify this.

Thanks to anyone who bothers to try this, and to anyone who can explain what I'm not understanding here.

JET

Getting 1346458189 ('PARM') error

$
0
0

From the readme:

"An Illustrator error occurred: 1346458189 ('PARM')" alert (1459349)    Affects: JavaScript    Problem:     This alert may be popped when badly written scripts are repeatedly      run in Illustrator from the ExtendScript Toolkit      Scripters need to be very careful about variable initialization and      namespace conflict when repeatedly pushing a batch of Illustrator scripts     for execution in Illustrator via the ExtendScript Toolkit (ESTK) in a      single Illustrator session. Each script run is executed within the same      persistent ExtendScript engine within Illustrator. The ESTK debugger      uses BridgeTalk to communicate with Illustrator. One global, persistent      ExtendScript engine inside Illustrator handles all BridgeTalk      communications. The net effect is that the state of the ExtendScript      engine is cumulative across all scripts that ran previously.      The following issues with script code can cause this problem:        - Reading uninitialized variables.        - Global namespace conflicts, like when two globals from different         scripts clobber each other.    Workaround:     Initialize variables before using them, and consider the scope of      your variables carefully. For example, isolate your variables by      wrapping them within systematically named functions. Instead of:             var myDoc = app.documents.add();       // Add code to process myDoc           Wrap myDoc in a function that follows a systematic naming scheme:             function myFeatureNameProcessDoc() {      var myDoc = app.documents.add();      // Add code to process myDoc      }      myFeatureNameProcessDoc();

 

 

This makes zero sense to me. If javascript variables are being reused or 'clobbered' or your javascript is 'poorly written' (this is not defined) it should have no effect on the scripting engine. Errors should cause exceptions to be thrown, which can be caught by the script.  I'm getting these errors when I try to evaluate properties of valid objects, for instance trying to access pathItem.fillColor. It's happening in various (almost random) lines in my script. Javascript doesn't have namespaces so I don't know what a 'namespace confilct' would be. Accessing variables from nested functions also seems to be a problem.

 

Edit - this seems to be related to accessing global variables or variables defined in containing functions. For now, adding var to the first use in subfunction seems to have fixed the problem. What is strange is you don't get an undefined variable error, it just crashes when it tries to access the properties.

 

Edit - still not fixed. I'm guessing it has something to do with memory allocation, because I am processing a lot of big raster images in todays batch of files.

 

Edit - processed 84 files today with no errors the pattern I'm using is to use a bach file that loops

 

"(Path)/Extend Script Toolkit.exe" -run script

sleep 10

 

The script opens a group of files (in my case JSON files), processes one file, exports an ai file, deletes the JSON file, then exits.

Link to a web page from AI javascript?

$
0
0

I've written a script with a ScriptUI interface, which other people will be using. I'd like to include a 'help' button in the interface, which ideally would connect to a web page with more details. (The alternative is to create the 'help' window in javascript, but the web page already exists and it would be a shame not to use it.)

 

From what I've read, other Creative Suite programs may be able to connect to the web with javascript, but apparently not Illustrator. Can anyone please confirm this is so? Or better, point me towards a solution!

 

With thanks.

Retrieve whats in the clipboard possible?

$
0
0

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

If so how?


Syntax for identifying Area Text which has overset text

$
0
0

Is there a way to identify if the Area Text box has overset text using Applescript? if yes, can some one let me know the syntax please.

 

Thanks in advance

 

Jaim

Saving documents via Scripts: Get current file name and set save path/file type

$
0
0

I am writing a script that will:

 

-Make all layers invisible

-Make a layer named "background" visible

-Delete all the invisible layers

-Save the docment as an EPS file (leaving the original document untouched)

 

I am new to scripts and so have based my script by copying code from other scripts.

 

Here is my code:

 

var doc = app.activeDocument;

var name = doc.name;

 

 

var hide = function (){ // hide all layers (based on http://forums.adobe.com/thread/644267)

     var L=doc.layers.length;

     for (j=0;j<L;j++){  doc.layers[j].visible=false; }

}

hide();

 

 

// loop through all layers

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

 

 

 

 

 

              // Create the illusrtratorSaveOptions object to set the AI options

    var saveOpts = new IllustratorSaveOptions();

 

    // Setting IllustratorSaveOptions properties.

    saveOpts.embedLinkedFiles = true;

    saveOpts.fontSubsetThreshold = 0.0

    saveOpts.pdfCompatible = true

 

 

 

 

 

 

//Set up Variable to access layer name

          var currentLayer = app.activeDocument.layers[i];

 

// Loop through the layers and make the back ground layer visible

          if (currentLayer.name == "Background") {

                    docName = name + currentLayer.name+".eps";

                    currentLayer.visible = true;

                    }

 

 

}

 

 

// Delete Invisible Layers (based on http://www.cartotalk.com/index.php?showtopic=7491)

var myDoc=app.activeDocument;

var layerCount=myDoc.layers.length;

for (var ii = layerCount - 1; ii >= 0; ii--) {

    var currentLayer = myDoc.layers[ii];

    currentLayer.locked = false;

    var subCount = currentLayer.layers.length;

    for (var ss =subCount -1; ss >= 0; ss--){

        var subLayer = currentLayer.layers[ss];

        subLayer.locked = false;

        if (subLayer.visible == false){

            subLayer.visible = true;

            subLayer.remove();

            }

        }

    if (currentLayer.visible == false){

        currentLayer.visible = true;

        currentLayer.remove();

        }

    }

 

// Save Out Document with New Name

 

var saveName = new File ( doc.path + "/" + docName );

doc.saveAs( saveName, saveOpts );

 

 

 

Everything works fine except:

1) It saves the document with the name AdobeIllustratorBackground as opposed to the name of the document

 

Also, I am not sure how to tell the script to save as EPS and to specify the save location.

 

Could some one give me some pointers?          Thanks!

Convert string (string of JSON) to JSON object?

$
0
0

**EDIT**

I finally figured out how to use #include instead of file.read();. This solves my immediate problem. However I am still curious as to whether it's possible to do what I'm asking for below, just in case there comes a situation where for whatever reason I cannot simply use #include. Thanks everyone. =)

**EDIT**

 

**EDIT 2**

Anyone know how to use #include for a file whose name is determined during script execution?

For example.. the variable orderNumber is generated by a prompt window (lets say the result is 1234567). the file i want to include will be named "1234567.js).

What I want to do is something like:

#include "~/Desktop/Info Folder/" + orderNumber + ".js"

(then I want to assign a variable to the result somehow, since it's simply an anonymous object at this point and i don't know how to access it's contents);

**EDIT 2**

 

Hey all. I have a (most likely really stupid) question about how to take a string that contains the JSON text and simply change it's type from "string" to "object"... I'm probably wording this very badly.

 

I'm fetching a .js file from my local network and setting a variable to the result of file.read();

 

The contents of the file is an anonymous object in JSON. However, when i use file.read(); the object is brought in as a string, like this:

 

'{"roster":[{"name":"Fink","number":"19","jerseySize":"XL","qty":"1","topId":"78531"},{thi s is the next player},{this is the next player}]}'

 

That is a massively simplified version of what i'm actually reading, but you get the point. I want to be able to bring that object into the script that I'm running and create new objects based on the pertinent information (in this case i only need the values for "name", "number", and "jerseySize").

 

So my question is this. how do i turn the above string of JSON into:

 

var roster = [

     {

     "name":"Fink",

     "number":"19",

     "jerseySize":"XL"},

     {

     next player

     },

     {

     next player

     }

]

 

???? A google search reveals the method JSON.parse(text). But that is not supported in ESTK.

Set unit preferences (Javascript)

$
0
0

I can't find a way to set the unit preferences for Illustrator CS6/CC using JavaScript.

 

I found that this works (setting units for stroke):

var units = 2; // 0-inches, 1-milllimeters, 2-points

app.preferences.setIntegerPreference("strokeUnits", units)

 

But I want to set the ruler units ("General" in the interface), and this does not work:

app.preferences.setIntegerPreference("rulerUnits", units)

 

Any help?

Peter

Extracting data from Excel To Illustrator javascript or vbscript

$
0
0

Hi all-

I was wondering if there was a way to extract data from Excel to be used in Illustrator. I know there is an option of variables and xml, and I don't want that. I've seen and tried out how to read illustrator and write to excel, and I get that.  What I would like to do is pretty much the opposite:

 

1.Pre-fill in an Excel file(.xls,.csv, doesn't matter) with data such as a filename in column 1 and (Replacement Text) in column 2 and close manually.

2. Run script(VBSCRIPT,Javascript, doesn't matter)

3.For each column in Excel file where cell in first column is not empty, open Illustrator Template with placeholder of "DWG" textframe and replace the frame titled "DWG" with Replacement text from Excel in Column2.

4, Save each to a PDF file and name file with text from Excel Column1(Filename)

 

In a nutshell, there will be a single illustrator template with a premade textFrame with a name of "DWG". Excel will contain two columns, one for the filename to be named and one for the relative text to replace with the placeholder in AI. I hoped I explained this well enough without causing too much confusion. Thanks in advance.

 

FilenameReplacement Text

test1.pdf

DWG01
test2.pdfDWG02
test3.pdfDWG03
test4.pdfDWG04

AI_Ex..PNGAI_Ex2.PNG

Viewing all 12845 articles
Browse latest View live


Latest Images

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