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

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!


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

Batch replace color with another color

$
0
0

Hi,

 

I would desperately need some assistance in trying to accomplish batch editing of ai-files via JavaScript.

What I would need to do, is go through a number (many!) of files, find items with certain swatch color (referenced by its name), and replace the item-fill with another swatch-color (also referenced by its name). Then save the document with another name.

 

Other parts I have managed to do, except find/compare/modify the fill color of an item.

I have gone through these forums and tried a number of things to a point where I am currently very confused and frustrated 

 

Some details (if it helps any), I'm using Illustrator CS3 and JavaScript.

Here's the closest where I got with trying to find a certain color and eventually changing it:

 

#target illustrator

var sourceFile, findColor, replaceColor;

sourceFile = new File().openDlg('Please select your Illustrator file…');

open(sourceFile);
var docRef = app.activeDocument;

findColor = docRef.swatches.getByName("vih");
// replaceColor not yet used anywhere
replaceColor = docRef.swatches.getByName("sin");

for(var obj = docRef.pageItems.length - 1; obj >= 0; obj--) {    if(docRef.pageItems[obj].fillColor == findColor) {        alert("Match found"); //It never seems to get here, so my comparison clearly is not working?    }    else {        alert ("No specified color found!");    }
}

docRef.close();

 

(and yes, I'm completely new with java-scripting, so even this is constructed from bits of sample-scripts and other scripts found from these forums)

 

Please, I would really appreciate any help, this can't really be such a difficult task to do... can it?

 

BR,

Johanna

Changing decimal values to fractions

$
0
0

Does anyone know of a good way to convert decimal values to fractions for use in inch measurements? I have a script that works great but it returns values like 5.5638 and I'd rather it return the closest fraction answer like 5 9/16. 1/16ths would be great, but I'd settle for 1/8ths.

 

I started trying to come up with a large if with lots of > and < conditions, but I figured if anyone has already done this it might be better not to reinvent the wheel.

 

Thanks.

All Group to Ungroup Script

Batch replace a colour with another colour

$
0
0

I have over 100 documents. In these documents, some of the objects use a regular black colour (e.g. C0, M0, Y0, K100). I need to replace it as a rich black (e.g. C75, M68, Y67, K90). The regular black colour is NOT saved as a swatch, so I can't just update the swatch. The objects are made of paths and shapes, some of which are in groups.

 

I found a script here and have updated it to suit my needs (The original script requires you to select an object, my update automatically selects all objects in the file). It works fine on a simple document that has a few layers. However, on more complex documents that have multiple nested layers, I get the following error:

 

Error 1302: No such element

Line: 9

->       myItem=docRef.pathItems[i];

 

 

Here is my code:

var docRef = app.activeDocument;

docRef.hasSelectedArtwork = true;

var iL=docRef.pageItems.length;

 

for (i=0;i<iL;i++){

     myItem=docRef.pathItems[i];

         

          if (myItem.fillColor=="[CMYKColor]" && myItem.selected){ //implement only for CMYK and selected

     var c1=0;

     var m1=0;

     var y1=0;

     var k1=100;

     var c2=Math.round(myItem.fillColor.cyan); // round the number ( 0,0012 => 0 )

     var m2=Math.round(myItem.fillColor.magenta); // round the number ( 6,8898 => 7 )

     var y2=Math.round(myItem.fillColor.yellow);

     var k2=Math.round(myItem.fillColor.black);

     if (c1==c2&&m1==m2&&y1==y2&&k1==k2){ // compare

     myItem.fillColor.cyan=75;

     myItem.fillColor.magenta=68;

     myItem.fillColor.yellow=67;

     myItem.fillColor.black=90;

      redraw();

                    } // if compare

                             

          } // if CMYK

     } // end for

 

How can I overcome the error.

Trouble assigning TextFrame to Justification.Left

$
0
0

Hello,

I need some help trouble shooting a script.

I am trying to flip the justification for all of a selected set of text frames. However, while most types of flipping work properly, the following does not

 

if(sel[i].story.textRange.justification == Justification.RIGHT){         sel[i].story.textRange.justification = Justification.LEFT;
}

 

I would expect the justification for items that are Justification.RIGHT to switch to Justification.LEFT, but they remain as Justification.RIGHT

It does not fail, it just does not work as expected.

 

What is odd is that it seems to work correctly for the three other types of justification I am flipping in the same script. See below for the full script.

 

Any ideas what is causing this?

 

try
{          // Check current document for textFrames.          if ( app.documents.length < 1 ) {                    alert ( "open a document with text objects and select them." );          }          else {                    docRef = app.activeDocument;                    if ( docRef.textFrames.length < 1 ) {                              alert ( "Select some text objects." );                    }                    //where text fames are selected swap the jusification                    else {                              sel = docRef.selection;                              var sellen = sel.length;                              for (var i=0;i<sellen ;i++)                              {                                        if(sel[i].typename == "TextFrame"){                                                  if(sel[i].story.textRange.justification == Justification.LEFT){                                                            sel[i].story.textRange.justification = Justification.RIGHT;                                                  }                                                  else if(sel[i].story.textRange.justification == Justification.RIGHT){                                                            sel[i].story.textRange.justification = Justification.LEFT;                                                  }                                                  else if(sel[i].story.textRange.justification == Justification.FULLJUSTIFYLASTLINELEFT){                                                            sel[i].story.textRange.justification = Justification.FULLJUSTIFYLASTLINERIGHT;                                                  }                                                  else if(sel[i].story.textRange.justification == Justification.FULLJUSTIFYLASTLINERIGHT){                                                            sel[i].story.textRange.justification = Justification.FULLJUSTIFYLASTLINELEFT;                                                  }                                        }                              }                    }          }                     
}
catch (e){          alert("Script Failed!\n"+e);
}

Restart illustrator through script (or eliminate PARM error)

$
0
0

I'm working on a javascript that goes through a folder, rasterizes the paths inside each file, and saves the results as separate files in another folder. My script works fine on individual files as well as for several simple files. However, once it gets going on some of the big ones, it starts to give me PARM errors.

 

What I'm working with:

  • Illustrator CS5.1
  • Windows XP, SP3 (work computer)
  • Javascript
  • The CAD export that created the pdf and eps files broke any curves into tons of tiny straight lines. As a result, these drawings can have 15-35 thousand paths per image.

 

Summary of my code:

  • Get the source and destination directories
  • Open a file from the source directory
  • Go to the first layer of the file
  • Loop through all text items to move them to their own layer
  • Loop through all path and compound paths to move them to a group
  • Rasterize the group of path items
  • Repeat for the next layer and so on
  • Save the file to the destination directory
  • Repeat the process for the next file and so on

 

The scripting guide suggests it could be from conflicting functions or global variables overwriting each other. However, my script is now entirely contained within its own function, and all variables are declared locally. Running from a clean illustrator and ESTK startup, it will still produce a PARM error after a few large files.

 

The guide also suggests having the script quit and re-launch Illustrator after working on many files. Since I assume these huge diagrams are probably several "normal" files' worth of objects each, I figured it probably just needs to restart Illustrator after x amount of stuff goes through. So I look in the guide's section on launching Illustrator through javascript. That basically says "Why would you ever need to do that?" Gee, thanks. I tried looking it up in the tools guide, but that document isn't very clear at all.

 

 

So, onto my actual questions:

 

1. What would I have to do so Illustrator doesn't throw a PARM error on the line marked below? (besides just putting it in a try/catch and pretending it didn't happen) It doesn't consistently happen on the same file or even at the same point in the file, but always at that line.

 

This is just a tiny part of the script. objectClass is a placeholder for PathItems, CompoundPathItems, etc. Looping backwards and setting the group to null at the end were just experiments, neither of which had any effect on the error.

 

if(objectClass.length > 0){    var objectGroup = myLayer.groupItems.add();    for(var i = objectClass.length; i > 0; i--){        objectClass[i-1].move(objectGroup, ElementPlacement.PLACEATBEGINNING); //This one keeps breaking stuff.    }    sourceDoc.rasterize(objectGroup, rastBounds, rastOptions);    objectGroup = null;
}

 

 

 

2. Failing that, how can I relaunch Illustrator through javascript? Or a limited amount of VBScript, though my knowledge of that is limited too.


Is it possible to create a panel with JavaScript?

$
0
0

Hi friends

 

As I´m studying JavaScript and the user interface creation...would like to ask (more for curiosity):

 

Is it possible to create a new panel for Illustrator using JavaScript? Or this is only possible using C++?

 

(in the Window Class UI we have the "palette" creation method..so wondering the result of it too)

 

Thank you a lot

Gustavo

Pg Number, File path and date automatically printed?

$
0
0

Is there a way to automatically print the page number, complete file path and date at bottom of each  page (set to landscape)?

 

Thanks!

Custom scripts not working in Illustrator CC (2014)

$
0
0

A couple of custom scripts that are part of my workflow don't work in the new CC; MultiExporter.jsx and Sprite CSS Generator.jsx.

When I try to run either a titled modal window comes up as if the script is running but the actual window is only a couple of pixels tall and can't be re-sized;export-win.png

sprite-gen-win.png

 

They both worked fine in CC. My grasp of javascript is pretty basic but is there code that needs to be changed to update these to work with the current version?

Thanks!

Bob

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.

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

Looping problem...How to create and lock a set of PathItems?

$
0
0

Greetings all!

I'm a noob....a very confused one

And I'm trying to get this thing work

So here is what I have. The first loop grabs the geometries drawn in the current document and rotates it around itself creating duplicates. The second loop is supposed to circumvent more geometries around the newly created geometries.

But instead of creating a radiant pattern, this code builds a tower: for the second loop everytime it grabs the last drawn geometry instead of what is in the "Original"

Can somebody explain what is wrong? Thanks!

 

for NumPaths = 1 to frontDocument.PathItems.count

          set myPath = frontDocument.PathItems.item(NumPaths)

 

 

          For index = 0 To 30

                    set newPath = myPath.Duplicate

                    call newPath.translate(100*sin(6.14* index/30),100*cos(6.14* index/30))

                    call newPath.rotate(360 * index/30)

          Next

Next

 

 

Set Original = frontDocument.PathItems

 

 

for NumPaths = 1 to Original.count

          set myPath = Original.Item(NumPaths)

 

 

          For index = 0 To 30

                    set newPath = myPath.Duplicate

                    call newPath.translate(100*sin(6.14* index/30),100*cos(6.14* index/30))

                    call newPath.rotate(360 * index/30)

          Next

Next

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


Calling functions from UI palette

$
0
0

Hello,

From what I understand, you can't call complex functions from a scripted UI palette, only from "dialog" windows (which are usless in my case) because I need the persistance of a palette.

 

I have a series of scripts in use now that are  accessed from the usual "file-scripts folder" within Illustrator itself (about 27 of them).  I want to script a palette window so users can acces them without the usual mouse clicks down the menu system.

 

I'm able to call a simple "Hello World" type function using the "onClick()" method from a button of a scripted palette window, but I cannot use my regular working scripts inside a function that's called from the button.  In X-Code, I was able to write my scripts individually, then just add them to a main floating window via a separate function when they were completed.  But, I'm finding Javascript a little more tricky.

 

If I copy my other's script code into the function in the palette window script, it runs, but it runs before I click the button! --  After in runs, then the palette window is displayed(?).  If I try to use the execute() method with "onClick", the script just opens in the SDK, it will not and does run in Illustrator.

 

I take both of these as clear indications that I have no clue what I'm doing (or that I'm trying to do the impossible).

 

I did find someone with a similar problem, but they were scripting After Effects and were offered this solution:

 

system.callSystem ('afterfx -r "/C/Program Files/Adobe/Adobe After Effects CS3/Support Files/Scripts/GlobalVars.jsx"');

 

 

Is there anything I can do in Illustrator that will allow me to call (or execute) my other scripts/functions and have them execute within Illustrator?

 

Thanks for any and all help!

Illustrator VBA scripting 101 - via Excel

$
0
0

This post will attempt to introduce newcomers to Illustrator Visual Basic Scripting (well, not actually vbs, but rather tru VBA, Visual Basic for Applications). I personally prefer vba over bvs for a number of reasons. First, I always have Excel and Illustrator open, so it makes sense for me use it to drive Ai. Second, I usually need to transfer data between the two programs. Third...I love the Excel IDE...ok, let's get right into it.

 

 

- Open Excel

- hit Alt+F11, to bring up the editor

- in the Tools menu, click on References...

- add a reference to "Adobe Illustrator CS5 Type Library"

- in the Personal.xls (or in any other book) add a Module. Personal is a global workbook that is always available. If you don't see it, go back to Excel and record a macro, anything will do. That will create the Personal file.

- and type the following in that module

- we have to continue the tradition and do the "HelloWorld" script

 

Sub helloWorld()    Dim iapp As New Illustrator.Application    Dim idoc As Illustrator.Document    Dim iframe As Illustrator.TextFrame       Set idoc = iapp.ActiveDocument    Set iframe = idoc.TextFrames.Add       iframe.Contents = "Hello World from Excel VBA!!"       Set iframe = Nothing    Set idoc = Nothing    Set iapp = Nothing
End Sub

 

- save Personal book

- open Illustrator and create a new document first

- to run, move the cursor anywhere inside the Sub...End Sub and hit F5

 

that's it for now...in the following posts we'll move the text to the middle of the page, create new documents, get data from an Excel Range to Illustrator, get data from Illustrator text frame to an Excel Range...and more, hopefully.

 

questions? comments?

Replace text as Bold

$
0
0

Hello, I need to replace some words to bold style. Havent found any info about font styles in adobe's script references.

 

Heres the algorithm:

 

1) open up a dialog box and ask to type in a word to find and to be replaced

2) find a word

3) replace the word's style to bold

4) search next word..

import excel data into text fields

$
0
0

i'm new to scripting in illustrator and was wondering if anyone could point me to resuources that will help me  create a script that pulls data from an excel or xml document into a variable text field in illustrator and then save the document as an eps or ai file. i've searched the forums and googled but haven't been able to find anything solid. thanks in advance.

[JS]: Accessing Menu Items in CS6

$
0
0

Hi,

 

So I just got CS6, and I'm wondering how I access menu items using Javascript?

Also, I'm looking at the CS6 JS reference, and it doesn't say whether app.activeDocument.selection is Read-Only. Hopefully not, because I would need this for my purposes in accessing the menu.

The item I wanna access is Select > Same > Stroke Color. Seems simple enough. Any help would be appreciated!

Viewing all 12845 articles
Browse latest View live


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