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

Access XML_ID of pageItem/groupItem

$
0
0

Is it possible to access the XML_ID of  a pageItem or groupItem via ExtendScript?

 

For example a layer name may be 'Active' but it's XML_ID (as viewed when setting Preferences > Identify Object By > XML ID) may be 'Active_1_' due to a copy and paste operation.

 

So the Object name would be groupItem.name  but there is no groupItem.id or groupItem.xml_id for example?

 

Does anyone know a way to access these?

 

Many thanks,

 

Michael


How do I copy active artboard from Illustrator to Photoshop?

$
0
0

Hi,

 

I need to copy the active artboard from Illustrator to Photoshop. Can this be accomplished? I got a handle to active artboard like this

 

//get artboard collection

var myArtboards = myDocument.artboards;

 

var activeArtBoardIndex = myArtboards.getActiveArtboardIndex();

var myActiveArtboard = myArtboards [activeArtBoardIndex];

 

any ideas on copying this artboard to a file in PhotoShop?

 

thanks for your help.

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.

JavaScript to prompt user to save as PDF

$
0
0

I am making changes with code to the file. I want the user to be prompted to save as a .ai file first. I have that down. Now I am wanting to have the user immediately be prompted to save as a pdf with only the optimize for fast web view option selected. I believe it is an adobe preset of Smallest File Size.

The reason for wanting the prompt is because I want to save the files in 2 different locations.

Here is my code so far.....

var doc = app.activeDocument;
// Save as .ai file 
var fileName = doc.fullName; 
var thisFile = new File(fileName);
var saveFile = thisFile.saveDlg();
doc.saveAs (saveFile);


// Save as .pdf file
var pdfSaveOptions = new PDFSaveOptions(); 
pdfSaveOptions.pDFXStandard=PDFXStandard.PDFXNONE; 
pdfSaveOptions.compatibility = PDFCompatibility.ACROBAT5; 
pdfSaveOptions.preserveEditability = false;  
var pdfFile = new File(fileName); 
doc.saveAs(pdfFile, pdfSaveOptions);

AI CS4 Windows 7 64bit

Is it possible to run an action with a script using cs6 javascript

$
0
0

In the pdf for the scripting guide it says :

 

"A script can execute an action, but actions cannot execute scripts."

 

I am having trouble finding out how to do that, and I know a way to have an action execute a script so that part is false haha. But if anyone knows how to have a script execute an action it would be very helpful to me. Thanks in advance!

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

)

Exporting an .ai file to a bitmap file

$
0
0

In Illustrator Scripting (VBscripting), how can you export an ai file to a bitmap file?

 

In Illustrator you can open an ai file and by selecting the Export option you have a choice of formats and one of them is BMP.  How can this be done in scripting?  I did look at the AIExportType, but BMP is not in the list.

 

aiJPEG = 1

aiPhotoshop = 2

aiSVG = 3

aiPNG8 = 4

aiPNG24 = 5

aiGIF = 6

aiFlash = 7

aiAutoCAD = 8

 

I will also need to do this same method by Exporting to an eps file.

 

The task is the following:

 

When a client uploads an image file, we need to automatically export the file to bmp and to esp, thus having 3 files (original upload, bmp, and esp).  The file types that we are exporting, so far, will be ai, esp, and pdf (more to follow I am sure).

 

We also need to get information about each file.

Is it vector or a bitmap?

Color:  RGB, CMYK, or Pantone?

Is there text or curves or both?

What is the DPI resolution?

What is the image size?

 

Any help would be beneficial.

 

Thanks,

 

Tom

 

 

 

 

 

 

 

 

 

 

 

 

open webpage

$
0
0

Hi guys, I was wondering if it's possible to open webpage with script:

 

WIN:  system.callSystem("cmd /c \"explorer http://www.google.com");

MAC: system.callSystem("open http://www.google.com");

 

It's definitely doable with After Effects, but does not work with Illustrator. Am I doing something wrong?

Also, in After Effetcs Preferences there's an option "Allow scripts to Write Files and Access Network" but cannot find anything similar in Illustrator.


So the question is - how to open web page once user hits a button in script UI?


Thank you.


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

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!

Imagetrace Script / doesn't recognize options / wtf preset number

$
0
0

Hello,

I'm totally desperate because I need to get an imagetracing script to work and it somehow just won't.
Here's the deal. I need to adjust the options for the trace command. There are 2 ways I can think of:

1) load a preset from the Application.tracingPresetList
array:
Well I tried preset number 1 to 25 and they load the default imagetrace presets but there is no way I could figure out to load my custom made presets. Also loading by name string doesn't work. This kinda sucks bigtime. Maybe there is a working way to write a custom preset in the array and then simply load it in my script?

2) set the tracingoptions right in the script:
and here is where my lack of javascript knowledge bugs me. I spent hours and hours browsing through code and read the javascript object reference but somehow illustrator just ignores my code. I guess it's a pretty simple job for someone who knows javascript. Here is the link to the reference guide. Tracing is starting at page 230 http://www.adobe.com/content/dam/Adobe/en/devnet/pdf/illustrator/scripting/...

Here comes the code. The bold part is where the options are set (or not..) and the commentary line is the preset part from option 1.
If someone could help me out. It's a biggie to me I will gladly buy you a case of beer, wire some coin on paypal, make you a video or whatever suits you. I'm realy loosing it, so please help!

Best Regards
rold
digitaldopamine.com

// Main Code [Execution of script begins here]

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

// Collectable files
var COLLECTABLE_EXTENSIONS = ["bmp", "gif", "giff", "jpeg", "jpg", "pct", "pic", "psd", "png", "tif", "tiff"];

var destFolder, sourceFolder;

// Select the source folder
sourceFolder = Folder.selectDialog( 'Select the SOURCE folder...', '~' );
//sourceFolder = new Folder("C:/Users//Desktop/1");

if(sourceFolder != null)
{
// Select the destination folder
destFolder = Folder.selectDialog( 'Select the DESTINATION folder...', '~' );       
//destFolder = new Folder("C:/Users//Desktop/2");
}

if(sourceFolder != null && destFolder != null)
{
//getting the list of the files from the input folder
var fileList = sourceFolder.getFiles();
var errorList;
var tracingPresets = app.tracingPresetsList;

for (var i=0; i {
if (fileList[i] instanceof File)
{
try
{               
var fileExt = String(fileList[i]).split (".").pop();
if(isTraceable(fileExt) != true)
continue;

// Trace the files by placing them in the document.

// Add a document in the app
var doc = app.documents.add(DocumentColorSpace.RGB,640,360);

    // Add a placed item
var p = doc.placedItems.add();
p.file = new File(fileList[i]);

// Trace the placed item
var t = p.trace();
myOpts = t.tracing.tracingOptions;
myOpts.cornerAngle = 180;
myOpts.fills = true;
myOpts.ignoreWhite = true;
myOpts.minArea = 0;
myOpts.pathFitting = 0;
myOpts.tracingModeType = 'TRACINGMODEBLACKANDWHITE';



// t.tracing.tracingOptions.loadFromPreset(tracingPresets[3]);

app.redraw();

var destFileName = fileList[i].name.substring(0, fileList[i].name.length - fileExt.length-1) + "_" +fileExt;
var outfile = new File(destFolder+"/"+destFileName);
doc.saveAs(outfile);
doc.close();
}
catch (err)
{
errorStr = ("Error while tracing "+ fileList[i].name  +".n" + (err.number & 0xFFFF) + ", " + err.description);
// alert(errorStr);
errorList += fileList[i].name + " ";
}
}
}
fileList = null;
alert("Batch process complete.");
}
else
{
alert("Batch process aborted.");
}

sourceFolder = null;
destFolder = null;

function isTraceable(ext)
{
var result = false;
for (var i=0; i {
if(ext == COLLECTABLE_EXTENSIONS[i])
{
result = true;
break;
}
}
return result;
}

launch illustrator with script from commandline

$
0
0

Hi,

(Illustrator CC 2014 on Windows 7)

 

I had hotkeys defined using AutoHotkey to execute a script in illustrator by executing a commandline, and with the script as an argument. This used to work fine, but it has suddenly stopped working for me, maybe with one of the latest Illustrator CC updates...

 

The command-line looks something like:

"C:\Program\Adobe\Adobe Illustrator CC 2014\Support Files\Contents\Windows\Illustrator.exe" "c:\pathtoscript\myscript.jsx"

Now Illustrator just sits there and nothing happens!

 

Has anyone else seen this? Can someone confirm if this worked in previous versions and also confirm that it doesn't in the latest, please?

 

Thanks!

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;

}

Ignore Empty Artboards?

$
0
0

I am using a slightly modified version of this script to export icons.

http://www.ericson.net/content/2011/06/export-illustrator-layers-andor-artboards-as-pngs-a nd-pdfs/

 

Say I have a document with three artboards named @1x, @2x, @3x, I am using the script to export each layer * each artboard to create my different size icons. Now the problem is that not every layer has artwork on every artboard. Is there a way to ignore empty artboards per layer? or At least how can I tell if an artboard is blank when a specific layer is selected?

ExportType.SVG "Use Artboards" option


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.

How to "Place as linked file" (not "import") a multipage PDF file on a single Artboard ?

$
0
0

ILLUSTRATOR CS4

 

Hello,

 

I often use the import multiPDF script from Carlos Santo and it works great.

But i sometimes get multipage PDFs from customers only with text, and the fonts are so rarely embedded.

As you may know, the solution to have this fonts "vectorised" even if you don't have it in your Font collection is to place your pdf as linked file (menu File-> Place with the "link" box checked) in an open document (or to drag and drop it), and then, via the Menu Object->Flatten Transparency, i check the box "Embed text" to have it done.

 

So to automate it with a multipage PDF, and inspired by Carlos' script, I tried this :

 

/////////////////////////////////////////////////

var doc = app.activeDocument;

app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

 

var pdfOptions = app.preferences.PDFFileOptions;

 

var firstPage = 1;

var lastPage = 10;

 

pdfFile = File.openDialog("Open Multi-page PDF", "*.pdf", false);

 

for (i= firstPage;i<lastPage;i++)

     {

         pdfOptions.pageToOpen = i;

         var  thisPlacedItem = doc.placedItems.add();

         thisPlacedItem.file = pdfFile;

     };

/////////////////////////////////////////////////

 

It doesn't work ! I end up with 10 placedItems of the page number 1 of the pdf file. Maybe that the pageToOpen option only works when i use the Open method ? In fact no, cause if i launch only the following 2 lines and then i drag and drop the pdf file, the page specified (page 8 in the example) is right placed.

 

//////////////////

var pdfOptions = app.preferences.PDFFileOptions;

pdfOptions.pageToOpen = 8;

/////////////////

 

I don't know how to do to fix it. I have 2 solutions but it only makes it "semi automatic" :

 

- Create a palette dialog with a button than increases one by one the pageToOpen option and then drag and drop my file one time for every pages (easy)

 

- Without the palette and the button, but with an event listener with a function that increases the pageToOpen value each time i drag and drop a new file (maybe by listening to changes in document.placedItems.length), but is it possible ?

 

Any suggestions ?

 

Thank you for your help!

illustrator Spiral Shrinking/Growin text, scaling down/up on spiral path

$
0
0

First of all thanks in advance for anyone who may assist, or make this even possible...... (please contanct me ADAM    razo.ad1985     --->G.mail)

 

In dire need of expertise assistante. Years ago I DLded this script and got this working and older illustrator. NOW i have Illustrator CS6. I would love/like to TYpe text on a spiral path, then have the abitly for "user input(entering custom values)" as far as

Font Start Size/Pt = 80

Font End Size/Pt = 12

 

Just a concept......(maybe someone can do this)

 

desired spiral script.jpg

 

 

Then have illustrator(script) perform action and make my spiral big(80pt) at beggning of text and end at small(12pt) there for looking as FONT/TEXT Gradually shrinks in size from beggining(80pt) unitl end of font/text(12pt)

 

   similar to this(end result after srcipt ran and values entered)

spiralText Concept.jpg

 

I know there is an older script out there..... but if someone can perhaps undate this and modernize it with prompt for user input/customization interaction

         ChangeSizesOfTextSelection.js  ----->    http://forums.adobe.com/thread/447657

Move corresponding text and overlapping graphics

$
0
0

OK so I have a JavaScript in CS4 that I wrote that will take selected text objects and create a layer formatted the way I need it.

For example the following text items are selected:

13   16   23   FF

The script will create the following layers:

Callout 013

Callout 016

Callout 023

Callout 0FF

 

There is always a circle and a line behind each text item. They look like this....(I have included screen shots of the objects properties)

Untitled-1.jpg


I am wanting my script to recognize the location of the items that overlap the corresponding text and after it creates the layer just send it all to the correct layer. So text object 13 would create the layer and the circle and line that are with it would go to the layer Callout 013. These items are not grouped. I am moving them manually right now but the volume I do I thought I would ask. This could be way too advanced and if it is I will continue doing it manually.

Here is what the final layers would look like after the script ran...

Untitled-2.jpg

Anyone willing to advise or help me figure this out? Greatly appreciate it!


ChangeSizesOfTextSelection.js

$
0
0

Illustrator version 10 installed with a sample script named ChangeSizesOfTextSelection.js. The script gradually changes the size of text.

 

The way it works is, you type some text in Illustrator, select it as an object, and run the script. The script incrementally decreases the size of the text until it gets to the center character, and then it incrementally increases the size of the text. This works in Illustrator 10. However, in Illustrator CS4 it doesn't do a thing. Below is a copy of the script.

 

I'd love it if someone could help out with a fix for the script so that it is usable in CS4.

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

 

// change size of paragraph text

 

//$.bp();

 

ChangeSize();

 

function ChangeSize()
{
    selectedItems = selection;
    // check to make sure something is selected.
    if (selectedItems.length == 0)
    {
        alert("Nothing is selected");
        return;
    }

 

    endIndex = selectedItems.length;

 

    for (index = 0; index < endIndex; index++)
    {
        pageObject = selectedItems[index];
        pageItemType = pageObject.typename;

 

        if (pageItemType == "TextArtItem")
        {
            // get the paragraphs from the selection.
            theTextRange = pageObject.textRange();
            paraTextRange = theTextRange.paragraphs;
            numParagraphs = paraTextRange.length;

 

            for (i = 0 ; i < numParagraphs ; i++)
            {
                aParagraph = paraTextRange[i];

 

                charTextRange = aParagraph.characters;
                charCount = charTextRange.length;

 

                if (charCount > 1)
                {
                    halfWay = Math.round(charCount/2);
                    fontSizeChanger = 36/halfWay;
                    currentFontSize = 48;
                    for (j = 0 ; j < halfWay-1; j++)
                    {
                        theChar = charTextRange[j];
                        theChar.size = currentFontSize;   
                        currentFontSize = currentFontSize - fontSizeChanger;
                    }
                   
                    for (j = halfWay; j < charCount ; j++)
                    {
                        theChar = charTextRange[j];
                        theChar.size = currentFontSize;
                        currentFontSize = currentFontSize + fontSizeChanger;
                    }
                }
            }
        }
    }
}

Viewing all 12845 articles
Browse latest View live


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