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

Script that gives specific names to layers - from bottom to the top

$
0
0

Hi,

 

This is probably an easy one for anyone with JavaScript experience.

I have 35 layers that I want to give specific names to (now they're named liked "layer 1, 2, 3" - but sometimes this won't be consistent, so some numbering might be skipped,

in other words I can't rely on a script that renames a specific "Layer 1" to "my name").

 

I want to rename each layer from the bottom to the top, i.e.:

[...]

"Power"

"Yellow"

"Hello"

 

With the script working its way up from the bottom to the top.

How do I accomplish this?

 

Thank you so much for you taking your time to help me.


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!

How do I target different version of Illustrator?

$
0
0

Using #target Illustrator from the toolkit want to open in AI 17.  I have both 17 and 18 installed but want it to run in 18.  How can I target each with the directive?

Transform all the Objects

$
0
0

How to transform (scale 50%) all the objects.

 

Note: is it possible without loop all the page items?

How to detect resolution with which file started?

$
0
0

Resolution may be modified and the i'm interesting in actual resolution.

Create artboard around group, unless there's a clipping path, then create the artboard around the clipping path

$
0
0

Hello again everyone.

 

I've been able to work out a bunch of this code from other people's questions, but i've hit a snag in my if/else clause structure.. I need to make an artboard around each top level groupItem on layer[0]. That part is cake.. unless there's a clipping mask. Visible bounds don't work when there's a clipping mask. So i built some for loops that cycle through the pathItems to search for the clipping mask and return the visibleBounds of said mask. However, i can't seem to work out how to structure the if clause in a way that will create the artboard around the clipping mask if there is one.

 

I'm successfully finding the visibleBounds of the mask and creating the appropriate artboard, but it's ALSO creating an artboard around the visible bounds of the entire group. How would i structure an if clause to determine whether an artboard was made around the clip path already and thus, not create a second artboard around the visible bounds of the whole groupItem? i imagine i'd need some kind of function to determine whether createdArtboardAroundClip = true and if so, skip this group..

 

Thanks all.

 

here's the code:

 

var aB = docRef.artboards;
var docLayers = docRef.layers;
var layer1 = docLayers[0];
var groupLevel1 = layer1.groupItems;

for (a = 0; a < groupLevel1.length; a++){    var groupLevel2 = groupLevel1[a].groupItems;    var vB = groupLevel1[a].visibleBounds       for (b = 0; b < groupLevel2.length; b++){        var paths = groupLevel2[b].pathItems;               for (c = 0; c < paths.length; c++){            if (paths[c].clipping == true){                var clipBounds = paths[c].visibleBounds;                aB.add(clipBounds);                break;                }            }        }    aB.add(vB);    }

using Javascript and ScriptUI to create a form that brings in a symbol from library

$
0
0

Hello everyone,

 

I've been trying to pull together the right info to use javascript to create a form to bring in particularsymbols from the symbol library based on the variables taken from the form. I've taken bits and pieces from various sample scripts and tried to make this work, but my problem appears when I try to use conditionals.

 

This is a limited version of what I want to do, but it is enough to get the point across.

 

1. I want to select a script that has various dropdown boxes. I would like the first dropdown to give me 3 options: 10, 13, 18

2. I would also like another drop down box that gives me three more options: single needle, double needle, and knife edge.

3. I would then like it to have an "ok" button and "Cancel" button.

4. From here when I click the ok button, a symbol is brought in from the library depending on what parameters were given to the form.

 

ex. If I selected 10 in the first drop down and double needle in the second, I would like "SYMBOL A" to be pulled from the library and centered on the artboard.

ex. If I selected 13 in the first drop down and double needle in the second, I would like "SYMBOL B" to be pulled from the library and centered on the artboard.

 

I've gotten the UI to pop up and it works as planned as well as bringing in a symbol, my problem comes when I try to incorporate conditionals and functions.

 

Here is my script. Please let me know what I'm doing wrong.

 

var myDoc = app.activeDocument;
var Pallette = new Window ("dialog", "Create a Shell");
Pallette.add ("statictext", undefined, "Fill Opening in Inches:");
Pallette.orientation = "row";
var myDropdown =  Pallette.add ("dropdownlist", undefined, ["10", "13", "18"]);
myDropdown.selection = 1;
var myButtonGroup =  Pallette.add ("group");
myButtonGroup.orientation = "column";
var btnCreate = myButtonGroup.add ("button", undefined, "OK");
MyFillSelection = myDropdown.selection
btnCreate.onClick = function () {
    if ( MyFillSelection = "13") {
               symbolRef = myDoc.symbols["SYMBOL A"];
        symbolItemRef1 = myDoc.symbolItems.add(symbolRef);
        
       redraw();
    } 

}
var btnCancel = myButtonGroup.add ("button", undefined, "Cancel");

  Pallette.show ();

 

If anyone has any input, it would be much appreciated.

 

thanks,

[Javascript] How to trim/crop an image for export

$
0
0

Hey folks,

 

Got lucky with an answer the first time, thought I'd try again.  In Illustrator CS5+, I'm looping through the objects in a document, exporting each of them to an image using exportArtBoardasImage().  They need to be trimmed afterwards, as they generally have a tonne of whitespace.  Normally, I run an ImageMagick shell script (mogrify -trim).  It'd be awesome if I could reproduce this functionality from within illustrator.  I've seen people handle this by copy-and-pasting each object into a new file, sizing the artboard to that object, exporting, then closing the file.  I'd rather not do this, as it's *way* too slow.  Any other suggestions?

 

Cheers!

 

-macdonaldshall


Convert Image Using Script (JSX)

$
0
0

Hi All,

 

I want to convert a AI file into a JPEG by using JSX(java script)

i am able to change its file type but having some problem with resizing

can anyone please suggest me some solution.

 

Thanks

ungroup all groups on an active layer(JavaScript).

$
0
0

Does anyone know how one would go about ungrouping all groups on an active layer with JavaScript?

Revert document?

$
0
0

Anyone know how to revert (or re-open) a document at the end of a script?

 

Cheers

Compare pathItem.fillColor to no fill

$
0
0

I am running a simple script that checks a certain layer for any circle that is not colored properly.

I have 4 circles and 1 line on my test document. I am checking to see if any items on a specific layer "Circles" exist.

 

Capture.JPG

Two circles filled and stroked correctly and two incorrect. Then a line (between the 2 red circles) is NOT supposed to be on this layer and has a fill color of None.

When I run the following script I get the output that there are 3 correct circles and 2 incorrect circles. The line between the red circles is coming in as correct. Any ideas why?

 

#target illustrator
var doc = app.activeDocument;
var allLayers = doc.layers;
var noColor = new NoColor();
var allLines = doc.pathItems;
var correct = 0;
var incorrect = 0;


for (var i = allLines.length - 1; i >= 0; i--) {  if (allLines[i].layer == "[Layer Circles]") {  if (allLines[i].strokeColor.gray == "100" && allLines[i].fillColor.gray == "0" && allLines[i].fillColor != noColor) {  alert("Correct");  correct++;  }  else {  alert("Incorrect");  incorrect++;  }  }  }


alert(correct + " correct circle and " + incorrect + " incorrect circles");


How to rotate a art board in a illustrator using adobe extended javascript

$
0
0

How to rotate a art board in a illustrator using adobe extended javascript

 

how to create mirror image of each textframe content of artboard

Assigning Text Fields Variables via VBScript

$
0
0

I'm looking to complete the first challenge of my project of repopulating text fields with translated text automatically.  To do this I need to pull the text down from an Ai file.  However, each text field must be identifiable so that it can be recorded into an excel spreadsheet.  So the spreadsheet would essentially contain the following data:

 

Column 1

 

File Name + Text1(this being variable name)

 

Column 2

 

English text pulled from that variable text field

 

Column 3

 

Translated text

 

So I need to code a script to batch through a folder of Ai files and assign each text field in the drawing a unique identifier or variable, i.e. "Text1", "Text2", etc...

 

I know that I can convert a text field to dynamic flash text which allows me to manually name a field, however doing this through script is less obvious to me, any help would be apreciated!

 

Furthermore, if there is already a unique identifier on textfields by default that I can tap into, that would be nice as well.  Otherwise I'd like to write a script that in the beignning of the code it steps through the number of fields and assigns each a unique identifier, copies that identifier to a spreadsheet, then next to that, copies in the text from the field into the spreadsheet as well.

 

Thanks,

-Chris

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?


Excel data to construct illustrator object

$
0
0

Problem:

How to read real number data from selected columns in an Excel spreadsheet into an illustrator javascript array variable, so that then I can use this information to construct an illustrator polygon. 

 

Further information:

I am new to javascript (and not much of a programmer in the best case, but do have some basic knowledge using ancient languages like FORTRAN 88). I am sure I am just missing an important step here despite all morning browsing with Google for answers (something to do with variable definition I assume?). I have some survey data defining the outline of features in map view listed in a string of point (x,y) values in adjacent columns in excel (these x,y point values calculated from GPS data using a commercial program to converted 3D position to a 2D x,y by geoid projection, and then in excel to re-scale point locations to illustrator’s artboard).  What I am trying to do is select columns of x,y value pairs in an excel spreadsheet, copy these values to the clipboard, and then develop an IA JavaScript to draw a polygon through the specified set of x,y points. It seems easy enough to script illustrator to draw the polygon once I get the values from the clipboard are in a javascript array (lots a good tips here http://scriptographer.org/tutorials/), but pulling in the clipboard data seems to be beyond me. I have tried populating a defined array with various combinations of array declarations and app.paste(); or windows.clipboardData.getData('text/plain'); with no satisfaction. I then had the idea to try to pull in the clipboard to one long continuous string, place that in a text box (see see its structure), andthen read and split up the text in a loop to populate the JavaScript array…but that deposited a complex illustrator table object into my text box, and several attempts to force the clipboard to paste text did not work (again probably having problems understanding variable type declaration).

 

Thanks very much for any suggests….and to be clear, I would be happy to find any method of scripting the pull of the selected on an excel spreadsheet for use in an Illustrator script…so if I am making this all harder than it needs, be I would be grateful to know that also!

Script path arrows

$
0
0

I cannot seem to find a complete description of the Adobe Illustrator object model, only the scripting guides, which are a good start but seem to provide only a partial list...does one exist?  My immediate problem is figuring out the script add arrows to path: e.g., "turn arrows on, for both sides of selected stroke, using  arrow head 3 scaled at 50%". Easy enough to do by hand using the stroke menu, but not obvious how to do it via a script. In case it matters to the answer, am still in CS5.1. Thanks for any help.

Finding bounds of nested clipping paths...

$
0
0

This topic has been touched on before, muppet & sonic have pointed me in the right direction, but I'm stuck right now....

 

Seeing as how "saveMultipleArtboards = false" is broken in CS4, and scripting any kind of epsSave results in the artboard size being the bounding box, I am trying to see if I can find out if the "visible to the eye" bounds of artwork exceed the artboard size.

 

I can easily find non-clipped objects hanging outside the artboard by comparing the document's visible bounds to the artboard size.

Likewise the "visible to the eye" bounds of clipped objects :

 

var docRef = app.activeDocument;

docRef.rulerOrigin = [0,0];

 

////Get size of artboard
var myDocsizeArray = [0,0,docRef.width,docRef.height]

 

////Check for items on page
if(docRef.pageItems.length != 0){

 

/////Find out if top item is clipping mask
if(docRef.pageItems[0].typename == "GroupItem"){
if(docRef.pageItems[0].pathItems[0].clipping == true){

 

////Compare its bounds to doc bounds
var myClipArray = docRef.pageItems[0].pathItems[0].visibleBounds
if((myClipArray[1] >  myDocsizeArray[3]) || (myClipArray[2] >  myDocsizeArray[2]) || (myClipArray[0] < 0) || (myClipArray[3] < 0)){
alert("Outside of artboard")
}        
}
}
}

 

However, this doesn't work if clipping paths are part of a nested groups. Is there a way to see if a clipping path's parent group is within bounds, or parent's parent group etc. is within bounds. I need to find the topmost clipping path that trumps all the others in any nested group.

 

Is that what recursive functions are for? ,,,,,,,,,,,

 

Something that can keep looking in a loop within itself?  Very instrospective!

 

thx

Fix Space (not in starting of line)

$
0
0

Hi All,

 

I am new to Illustrator Scripting. But I am from Indesign Backround.

 

First script in Illustrator

 

Request:


1. Need to fix the double or more space into single space.

 

2. But need to retain in the starting of line.

 

Refer the Input and Output Screenshot:

Screen Shot 2015-01-07 at 17.18.39.png

 

Trying Code:

 

Below code helps to fix space in starting of line (but that is not my request)

var myDoc = app.activeDocument;
var myTF = myDoc.textFrames;

for(i=0; i<myTF.length; i++)
{    var myLines = myTF[i].lines;    for(l=0; l<myLines.length; l++)    {    var myOutput = myLines[l].contents.replace(/\s/g, "");        myLines[l].contents = myOutput;        }    }

 

 

And, please refer good pdf or tutorials for Adobe Illustrator.

 

Thanks in advance

Siraj

Batch saving AI files as low res PDF's

$
0
0

I need to find a way to convert a LOT of ai files, individually, to low res pdf's.

Preferably with the presets I want, not some defaults.

I'm not interested in an action. I was hoping for a droplet, script, or something similar.

 

I did find this and it looked promising...

 

http://xcorr.net/2010/05/12/batch-export-ai-files-to-pdf/

 

That almost worked.  Ultimately, for some reason, it couldn't see the ai files sitting in the specified folder.

 

I'd appreciate any help.

 

Runnign CS5 with MacOS 10.8.2

Viewing all 12845 articles
Browse latest View live


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