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

Script to round fractional CMYK colours?

$
0
0

This script must exist but I'll be damned if I can find it!!!

 

I work in a large printing company and we get artwork from all over that has dodgy CMYK colours (quick convertions from RGB obviously). We have noticed that these colours don't rip as well as rounded CMYK colours, so we spend a lot of time cleaning them up and rounding them down...

 

I'd like to be able to just run a script that does this to a whole document, including the colours inside gradients. So if for example the number is .5 or below we round down, or above we round up.

 

Does this exist, does anyone know?

 

CHEERS!

S


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?

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!

Extract text from illustrator for translation then replace with translated text

$
0
0

I am trying to find a way to expedite translations of our drawings.  Each drawing has a series of callouts showing what that piece of the drawing is via text.  I would need to do 100's of drawings for each book.

 

Questions:

 

1. Can I write something to batch a folder and extract the name of the file, and the text from each textbox so that when I get the translation back, I can automate the reinsertion of the translated text to its correct field (i.e. TextField1 = "Translate this" then repopulate that same exact field with "Translation")?  In order to do this I would think each text field would have to be tagged with some unique identifier so that it would know which translation goes where in the drawing.  Keep in mind, I'm ok with manually tagging each textbox if necessary.

 

2. Assuming the above is possible, what would be the best program to write the extracted text to so that reading and writing the translated text back into the drawing is as easy as possible (i.e. Word, Excel, PDF)?

How to save illustrator file without save as dialog ?

$
0
0

I' trying to save a file using 

 

app.activeDocument.saveAs(savepath);

 

and i am doing it in a loop on multiple files, but every time it will just show save as window and i have to do it manually.
Any ideas how to ignore that save as window ?

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.

Problem when passing value to resolution (Export TIFF)

$
0
0

I´m passing by a strange script behaviour. I´m trying to refine a script to export artboards as TIFF.

 

So suppose I started "var op = new ExportOptionsTIFF()"

 

And I set op.resolution = 250

 

Now I try to run this script via Extended Script Toolkit. I press play and it goes right...But If I make more tests I have this problem:

 

If I set a differnt resolution (for example, 365) the Script will ignore this new and will use the only value 250 defined in the past (in my first test). If, for a third time, I set another new value, the Extended Script will ignore this value and use the 365 I set in a previous test.

Look´s it´s recording the differnt values I put but it is always delayed one or two times :/

 

Do not know if I was able to better explain the problem.

 

Have you already passed by it?? Should I consider this as a problem? Or it´s only an Extendes Script software mistake?

 

Thank you a lot

Gustavo.

UI (Window, dialog, palette etc) reference info for AI scripting

$
0
0

I'm looking for standard reference info on UI elements like popup windows (dialogs, palettes etc). I've been through the Illustrator CS6 Javascript Scripting reference guide and also the CS6 Scripting guide, checking every mention of the words "Window", "Dialog", "Palette" etc (there aren't many), plus related terms like "edittext" and "slider" (which seemingly don't exist in these documents at all), and can't find what I'm looking for.

 

----------

 

I'm trying to script a simple info box that contains information generated by a script that doesn't need to be closed before the user continues working.

 

All I'm trying to find out is the basics. From looking at other scripts I've figured out that you can create a popup box like this:

 

var box = new Window('dialog', 'Some title');

var panel = box.add(panel, undefined, 'Panel title');
panel.add('edittext', undefined, 'Default value');
panel.add('slider', undefined, /*Default numeric value*/,/*min*/,/*max*/);

var group = box.add(group, undefined, 'Group title');
group = area_len_box.add('group', undefined, 'Title (not displayed)');
group.orientation='row';
group.closeBtn = group.add('button',undefined, 'Close', {name:'close'});
group.closeBtn.onClick = function(){
  box.hide();  return false;
}

...which is enough for a very rudimentary input system, but one which has to be closed before the user can return to their work - and I can't find any resource that gives the full options:

 

  • What are the other options for 'new Window'? I'm aware of 'palette' which appears to need an array of four co-ordinates like [20,20,100,100], but it clearly needs something else too as every palette I've made instantly closes. And what else is there beyond Window and Palette?
  • What other input devices are there beyond edittext and slider, and what parameters do they each need?
  • What can go in the "undefined"s I see everywhere these are used?
  • etc etc

 

There must be a reference to this somewhere, but I can't find it.


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

Simple InDesign script -> Illustrator help

$
0
0

I have this script by Peter Kahrel that reverese the order of letters in InDesign.

 

I need an Illustrator version of it. Can anybody help?

 

---------------------

//ReverseText.jsx

//An InDesign Javascript that reverses the order of any selected text.

//If no text is selected with the Type tool, nothing happens.

//Written by Peter Kahrel for InDesignSecrets.com

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

 

#target indesign

if ( "TextWordLineParagraph".search ( app.selection[0].constructor.name ) < 0 )

    exit();

s = app.selection[0].contents;

s = s.split("").reverse().join("");

app.selection[0].contents = s;

-------------------

 

Mainly using this for Arabic text in CS 3 and 4 for clients that don't have new versions - and will never buy it apparently.

 

Works great in InDesign. I've been putting the text in ID and then copying it into Illustrator. But it would be nice to skip that step if possible.

 

Thanks in advance.

List missing fonts in Illustrator

$
0
0

Hi all,

 

I've been working on a script to try and build a list of font's that not loaded in Illustrator. I know that Illustrator will alert missing fonts when a document is opened but this routine will be part of a larger script that will have the user dialogs turned off. My process is to build a list of fonts that are available to the the application, then build a list of fonts that are used within the active document and cross reference them to see if there are document fonts that are not in the application fonts list.

 

I have used a great function that I believe was posted originally by Moluapple and with some some brilliant advice from the always helpful CarlosCanto I thought that I had found the soultion but it appears to have some limitations. If I get a list of fonts available to the application and the document that I want to cross reference them against is open, the list that's returned contains fonts that are used in the document. Then when I get a list of fonts used in the document and cross reference them they will all be in the application list regardless of whether they're loaded or not.

The only way that I can get accurate results are if I run the script without any documents open and build a list of application fonts, then open a document and build a list of document fonts and then cross reference. This is the only way I can find out what fonts aren't loaded.

 

Does anybody know of another way to build a list of missing fonts without having to close documents first? I have searched through the XMP data and this doesn't seem to give me any clues and I've tried writing the code in applescript but it appears to work in the same way. Any help or comments would be welcome.

 

Here's my code:

 

#target illustrator

 

 

var doclist = app.textFonts

 

 

var appFontList = new Array ();

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

    var fontName = app.textFonts[i].name;

    appFontList[i] = fontName;

    }

 

 

var myfile = File.openDialog ('Choose a file');

app.open (myfile);

 

 

var docFontsList = getUsedFonts(activeDocument);

 

 

// function accredited to Moluapple

 

 

function getUsedFonts (doc ){

     var xmlString = new XML(doc.XMPString);

     fontsInfo = xmlString.descendants("stFnt:fontName");

     var ln = fontsInfo.length(), arr = [];

     for (var i = 0; i<ln; i++){arr.push(fontsInfo[i])};

     return arr;

}

 

 

var missingFontsList = checkFonts();

alert(missingFontsList);

 

 

function checkFonts(){

    var fontArray = new Array ();

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

        var thisDocFont = docFontsList[i];

        var activeFont = false;

        for (j = 0; j < appFontList.length; j++){

            var thisAppFont = appFontList[j];

            if (thisDocFont == thisAppFont){

                activeFont = true;

                }

            }

        if (activeFont == false){

            fontArray.push (thisDocFont);

            }

        }

    return fontArray;

    }

 

 

Many Thanks,

Nik

Batch combine files into one illustrator document - how to open target document?

$
0
0

I am making a script which will:

 

1) Open a folder of Illustrator files

2) Open each file in the folder (these files are called the source files)

3) Select all the contents of the source file

4) Copy the contents of the source file

5) Paste these contents into a target file as a new layer

6) Ensure the new layer has the same name as the old source file

 

 

However, I don't know how to tell Illustrator where my target file is. How can I do this?

 

Also, when I paste, how can I turn off paste rembers layers. (So the layers get pasted into the new layer that has the same name as the old document).

 

Here is my code:

 

 

// JavaScript Document

 

 

//Set up vairaibles

var destDoc, sourceDoc, sourceFolder;

 

 

// Select the source folder.

sourceFolder = Folder.selectDialog('Select the folder with Illustrator files that you want to mere into one', '~');

 

 

// If a valid folder is selected

if (sourceFolder != null) {

          files = new Array();

 

 

          // Get all files matching the pattern

          files = sourceFolder.getFiles();

 

 

          if (files.length > 0) {

                    // Get the destination to save the files

                    destDoc = document.selectDialog('Select the final saved document', '~');

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

                              sourceDoc = app.open(files[i]); // returns the document object

 

                              var myLayers = sourceDoc.layers; // All layers in Active Document

 

 

                              //Go through all layers of source document and copy artwork

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

                                        myLayers[i].hasSelectedArtwork = true;

                              };

 

 

                              with(sourceDoc) {

                                        var count = pageItems.length;

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

                                                  pageItems[i].selected = true;

                                        }

                                        redraw();

                                        copy();

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

                                                  pageItems[i].selected = false;

                                        }

 

 

                              }

 

 

                              //Create a new title variable that has the title of the source document

                              var title = sourceDoc.name;

                              var title = title.substring(0, title.length - 4); //(remove extension from name)

                              //Close the Source Document

                              sourceDoc.close(SaveOptions.DONOTSAVECHANGES);

 

 

 

 

                              //Open the Destination Document and create a new layer in it that is named after the title variation

                              var newLayer = destDoc.layers.add();

                              newLayer.name = title;

 

 

                              //Paste into this new layer

                              destDoc = app.paste();

 

 

                    }

          }

          else {

                    alert('No matching files found');

          }

 

}

 

Thanks in advance for any help   

 

Edit: Also, when pasting, how can I paste in place instead of just pasting.

CAN AN EXCEL XLSM FILE READ FROM A CSV AND WRITE BACK TO THE SAME XLSM -VBA

$
0
0

Hey Carlos- Here's the repost. 

 

Could an XLSM file read a line from a CSV file in "A1" and depending on what was in the first column in the XLSM, search the CSV file and find the indexed item in the second column or third? I've done it before with standard VLookup functions and it was cumbersome and very slow, and for some reason, everytime I would save the file it would take forever although the xls file was a single sheet.

 

i've attacthed a sketch of what I'm talking about, because it's hard to explain and I think the sketch explains it better. Here it is, sorry if it is blurry, it looked fine before I posted:

xlsm example.PNG

choose folder default location

$
0
0

Hi,

 

I've been searching the forum to try and a way to allow a user to choose a folder from a default location. I thought I had found the solution but it's not quite working as I wanted:

 

#target illustrator

 

 

//Example 1

var output_folder = Folder.selectDialog ('Choose PDF output folder.');

 

 

//Example 2

var myFolder=Folder(app.activeDocument.path).selectDlg("Choose PDF output folder:");

 

If I use the code in example 1 the choose folder dialog appears and the 'Open' button is available and when I press the button the location is chosen as expected. However if I use the code in example 2, although the choose window opens in the path of the active documents location the 'Open' button is not able to be pressed until I select a folder., which means that the chosen location is not correct. I should indicate that I'm running this code on a Mac.

 

Does anybody know a way to have a choose folder dialog window specify a location and be able to select that.

 

Thanks,

Nik

A Script to Find and Replace Layer Names

$
0
0

Are there any scripts to find and replace layer names?

 

There is an excellent script available for Photoshop which allows you to not only replace words in layer names, but also insert words as Prefixes, Suffixes and Sequential Numbers.

The illustrator version of this script only allows sequential numbering: It doesn't offer find and replacing of words.

 

Ideally, it would be great if there was something that could do multiple find and replaces in one go:

(e.g.

You have layers like this Car, Dog, Bat

You enter: car(Option1), dog(Option2), Bat(Option3)

Your layers then become: Option1, Option2, Option3).

)


Open Save File Dialog with Default Path

$
0
0

Hi All,

 

 

I want to open a "Save File Dialog " with some default path.

 

Like when user run that script I want to open  a "Save As" dialog box with default path "/Volumes/<shared name>/<folder name>/.. ."

 

I am using

 

File.SaveDialog(prompt, filter);

 

but it doesn't open to the location by default that I want to open.

 

Thanks

Harsh

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!

[TUTORIAL] ADD YOUR OWN KEYBOARD SHORTCUTS TO YOUR JSX SCRIPTS

$
0
0

This is for Windows only; it uses a feature to launch your favorite software via a keyboard shortcut. It’s been here for a while but it just never occurred to me to use it for this purpose.

 

1.       Create a shortcut on the Desktop that points to your script.

2.       Assign a keyboard shortcut to it. That’s it!!!!

 

 

If you don't know how, here’s a step by step

 

1.       Open the folder where all your scripts live

2.       Right click on any of them and click on “Send to …” -> “Desktop (Create Shortcut)”

3.       (Optional) Rename the shortcut; to help you remember it is a good practice to include the actual key combination

4.       Right click on the shortcut, click on “Properties”

5.       The Shortcut Key says “None”, place the cursor there and hit for example Ctrl+Alt+8

6.       Click on “Apply” then on “Ok”

7.       That’s it, go to Illustrator and hit your key combination.

scriptShortcut.png

 

Notes:

1.       Add the following line to the beginning of all your jsx scripts “#target Illustrator” (without the quotations)

2.       If there are duplicate key combinations, your newly created shortcut will take precedence over any existing Illustrator shortcut used for something else, so…to help you see what key combos are available:

 

          1.       In Illustrator, go to “Edit” -> “Keyboard Shortcuts…”, then click on “Export text…”

          2.       The file is saved as a text delimited, open it with Excel or similar program to be able to sort

          3.       This is what I get, a sorted list that easily shows what’s available

sortedShortcutList.png

 

3.       If you have lost of scripts, your desktop will soon be overcrowded with icons, which many people really hate. An alternative could be to create a shortcut to the folder containing all your scripts and assign a key combination. When you’re in Illustrator and use the key combo the folder will open and you will have to double click on the file to run it. Not ideal….but your desktop will be uncluttered and is still better that going to the menus to run your scripts.

 

any comments or questions are welcomed

embed all fonts in eps

$
0
0

I have a lot of existing eps-files of which the option "embed all fonts" is unchecked.

Know I have to check the "embed all fonts" in the existing eps-files.

I tried to modify the script below, but it seems that the embedallfonts is NOT working.

 

When I do it manually (without script), then it works fine. With script, it doesn't work.

 

 

 

#target illustrator

 

// PART 1

var doc = app.activeDocument;

 

// PART 2 -> herbewaren eps als eps

var destFile = new File(decodeURI(doc.fullName).replace(/(?: \[Converted\])?\.eps$/, '.eps'));   // also remove "[Converted]" from filename

var options = new IllustratorSaveOptions({});   // new save as options

options.compatibility = Compatibility.ILLUSTRATOR15;   // save as CS5

options.embedICCProfile=true;

options.embedAllFonts=true;

options.pdfCompatible = true;

options.useCompression = true;

doc.saveAs(destFile,  options);  // save the file in the same foldere as the eps

 

// PART 3

doc.close(SaveOptions.SAVECHANGES);   // close the file with saving

 

 

Another question will be: can I get a dialog box to put in the path to the eps-files, I can do thereafter it in batch instead of each time opening and closing a file.

Break text area into text lines

$
0
0

I want to break text area with line breaks in it into seperate text lines using return as delineator. for example

 

"Line 1

Line 2

Line 3"

 

I would like as

 

"Line 1"

"Line 2"

"Line 3"

 

I could probably write something but curious if someone already wrote it. I found a few similar ones like

http://forums.adobe.com/thread/321610

 

but they seem to be broken for CC here is the script in case you're curious

 

/////////////////////////////////////////////////////////////////
//Divide TextFrame v.2.2 -- CS and up
//>=--------------------------------------
// Divides a multiline text field into separate textFrame objects.
// Basically, each line in the selected text object
// becomes it's own textFrame. Vertical Spacing of each new line is based on leading.
//
// This is the opposite of my "Join TextFrames" scripts which
// takes multiple lines and stitchs them back together into the same object.
// New in 2.1 now right and center justification is kept.
// New in 2.2 better error checking, and now will run on more than one text frame at a time.
//>=--------------------------------------
// JS code (c) copyright: John Wundes ( john@wundes.com ) www.wundes.com
//copyright full text here:  http://www.wundes.com/js4ai/copyright.txt
//////////////////////////////////////////////////////////////////


var doc = activeDocument;
var genError= "DivideTextFrame must be run on a point-text text-frame. ";
var ret_re = new RegExp("/[\x03]|[\f]|[\r\n]|[\r]|[\n]|[,]/");
if(doc){
        var docsel = doc.selection;        var sel = [];    //remember initial selection set         for(var itemCt=0, len = docsel.length ;itemCt<len;itemCt++){             if(docsel[itemCt].typename == "TextFrame"){                  sel.push(docsel[itemCt]);             }         }            if(sel.length){  //alert(sel.length+" items found.");            for(var itemCt=0, len = sel.length ;itemCt<len;itemCt++){                divide(sel[itemCt]);            }             }else{                alert(genError +"Please select a Text-Frame object. (Try ungrouping.)");        }      
}else{    alert(genError + "No document found.");
};

function divide(item){
             //get object position    var selWidth = item.width;
if(item.contents.indexOf("\n") != -1){          //alert("This IS already a single line object!");
}else{           //getObject justification    var justification = item.story.textRange.justification;             //make array          var lineArr = fieldToArray(item);          tfTop = item.top;          tfLeft = item.left;          item.contents = lineArr[0];          //for each array item, create a new text line          var tr = item.story.textRange;          var vSpacing = tr.leading;    var newTF;          for(j=1 ; j<lineArr.length ; j++){                    newTF = item.duplicate(doc, ElementPlacement.PLACEATBEGINNING);                    newTF.contents = lineArr[j];                    newTF.top = tfTop - (vSpacing*j);        if(justification == Justification.CENTER)        {             newTF.left = (tfLeft + (selWidth/2)) - (newTF.width/2);        }    else            if(justification == Justification.RIGHT)        {            newTF.left = (tfLeft + selWidth) - newTF.width;        }    else    {           newTF.left = tfLeft;    }                    newTF.selected = false;          }
}


function fieldToArray(myField) {                     retChars = new Array("\x03","\f","\r","\n");                    var tmpTxt = myField.contents.toString();                    for (all in retChars )                    {            tmpArr = tmpTxt.split(retChars[all]);                    }                     return tmpTxt.split(ret_re);          }    }
Viewing all 12845 articles
Browse latest View live


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