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

Export Action As Script

$
0
0

I have recorded an action on one of my documents in illustrator. I would like to export this action as a file that shows the contents of this action in JavaScript, or, if that's not possible, in any script so I can make some variations to it manually. I've been searching for how to export an action as a script and haven't found any information. If a script file is not possible, is it possible to export some sort of log? Maybe I'm just looking in the wrong places, but any help would be appreciated.


Raster resolution

$
0
0

Hi, I'm trying to create a script that will rasterize an object with certain resolution, but to no avail, what am I doing wrong, can anyone give me a hint?

 

 

#target illustrator

 

 

function rasterItem() {

    var sourceDoc = app.activeDocument;

    var currentItem = sourceDoc.pathItems[0]

    var resolucao = rasterizeOptions.resolution = (resolution / 72) * 400;

    currentItem.selected = true; 

    activeDocument.rasterize( currentItem, currentItem.visibleBounds, resolucao ); 

rasterItem();

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;

}

Script to Rename Artboards with Layer Names

$
0
0

I'm looking to create a script to batch rename a number of artboards.

 

- I have 100 named layers.

- I have 100 artboards.

- I would like to rename the artboards to match the layer names.

- The layers are organized in the same descending orderas the artboards (ignoring the actual artboard names*).

- The topmost artboard (1 in the list) would be renamed "newspaper", the second artboard would be renamed "typewriter", the third artboard would be renamed "books", etc.

 

*in the example below the artboard named "Artboard 7" is actually the 6th artboard in list.

LayerNames-To-Artboards.png

 

Any help would be wonderful.

How do I get the position of the selected PathItem in pixels ?

$
0
0

Hi,

 

I have a simple problem, but can't seem to find my way around it:

 

I have PathItem and Illustrator points out that it is at position (781px,250px).

How can I get those values in jsx ?

 

I've noticed that the PathItem inherits the position property from PageItem, and position

is a point, but when I try prining the values, I get undefined:

 

$.writeln(app.activeDocument.selection[0].position.x);

 

If I leave out .x from the line above I get this printed in the console:

 

521,510

 

What are these values ? Are they x,y coordinates ? In what unit ? How can I convert to pixels ?

Why can I not access x,y/top,left properties (always get undefined) ?

 

I'm using Illustrator CS5.

Setting the bleed in AI via Javascript

$
0
0

Hi All,

 

I'm writing a function to change the artboard size and add bleed depending on certain conditions.

I can't actually believe this is causing me trouble but here it is, I'm trying to set the bleed dimensions in AI document with Javascript. All I've found so far is setting up PDF export options or print options, but not the actual artboard Document Setup. I just want to be able to set bleed to a newly created document like in this window:

So similar to Indesign:

 

with(myDocument.documentPreferences){  documentBleedUniformSize = true;  documentBleedTopOffset = 7;  }

 

(CC2017)

Screenshot 2017-04-06 15.45.28.png

Transform Each

$
0
0

Hi all,

 

i'm working on a script and final step is missing, i just want to know Transform each function code on JavaScript, or at least i want to create a code can do a shortcut like (Alt+Ctrl+Shift+D)

 

 

Object > Transform > Transform Each with Reflect X and Center point position

 

image.png

 

 

7.png

 

 

is it possible??

 

 

Thanks a lot

 

How to reflect in script?

$
0
0
Hi,

I want the equivalent of choosing Object > Transform > Reflect, across the Vertical axis. How would I do this with JavaScript?

Thanks,

Max

Illustrator Find And Replace

$
0
0

Hi there,

 

Can anybody tell me if it's possible to JavaScript Illustrators Find And Replace text function?

 

I know it's possible in InDesign but I can't find anything for Illustrator.

 

Many Thanks,

Nik

Change Folder.current to location of script (.jsx) file?

$
0
0

All,

 

I'm trying to use some images in my ScriptUI dialog, but I want to use a "relative" path name, and I can't seem to get it to work.

For example, this myScript.jsx works just fine, but as you can see, I'm using an "absolute" path name to transparencyGrid.jpg:

 

var w = new Window ("dialog");
var f = new File ('~/Desktop/transparencyGrid.jpg');
w.add ("image", undefined, f); 
w.show ();

 

However, I want to be able to use a relative (to myScript.jsx) path to point at transparencyGrid.jpg, like this:

 

var w = new Window ("dialog");
var f = new File ('../../../transparencyGrid.jpg');
w.add ("image", undefined, f); 
w.show ();

 

But, I can't seem to get this to work because relative paths seem to be relative to the current folder, Folder.current, not the location of the currently executing script.

I say that because when I do this:

 

alert(Folder.current);

 

The only thing the alert message shows is a backslash (/), indicating to me that the current folder is the root of my OS, but I thought it would be the folder where myScript.jsx resides.

 

So, is there a way of setting Folder.current to the location of the actual script?

Writing linked files name into AI file

$
0
0

Hello. I'm looking for a little help customizing the script below.

 

I would like the script to:

  1. Not include the file extension of the linked file in the file name
  2. Position the placed text relative to the top left hand corner of the linked file (not relative to the AI artboard)
  3. My linked file names have spaces in them. I would like the placed text to replace the "%20" with an actual space

 

//var Sel_itemPlaced = app.activeDocument.placedItems[0]; // if nothing is selected - use the first linked file item  
var sel_itemPlaced = app.activeDocument.selection[0]; // be sure that a linked item (and not an embedded) is selected  
//alert (sel_itemPlaced.file.name);  
var aTF = app.activeDocument.textFrames.add();  
aTF.position = [50,-50];  
aTF.contents = sel_itemPlaced.file.name; 

 

Many thanks so far to pixxxel schubser who has helped me get this far. This request spawned from Linked files name.

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?

`Custom Transparency Flattener Options` is available during FILE>Save as EPS file, But not available EPSSaveOptions???

$
0
0

How to access to `Custom Transparency Flattener Options` during method .saveAs()?

Export Action As Script

$
0
0

I have recorded an action on one of my documents in illustrator. I would like to export this action as a file that shows the contents of this action in JavaScript, or, if that's not possible, in any script so I can make some variations to it manually. I've been searching for how to export an action as a script and haven't found any information. If a script file is not possible, is it possible to export some sort of log? Maybe I'm just looking in the wrong places, but any help would be appreciated.

Changing the color of a selection to HEX

$
0
0

Hi guys,

i'm new to illustrator scripting (but not to javascript or programming).

I have an AI file that has multiple layers. each layer has several items that are supposed to be of same color.

I have an array of HEX values.

I would like to loop over all items in a single layer, select them and change their color to some given HEX.

Once that works, I will run on all HEX entries in array and save each variation in a separate PNG file.

 

For the first part i wrote some script (see below), but i do not see any change in the file after i run the script. No errors and no change.

I run the script once i select all items in a specific layer.

 

Can you please advise what am i doing wrong?

Thanks in advance!

 

My code:

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

 

function hexToRgb(hex) {

    var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);

    return result ? {

        r: parseInt(result[1], 16),

        g: parseInt(result[2], 16),

        b: parseInt(result[3], 16)

    } : null;

}

 

 

var fillRGBColor = function (pathItem, r, g, b){

    pathItem.fillColor.red = r;

    pathItem.fillColor.green = g;

    pathItem.fillColor.blue = b;

}

 

 

var fillHexColor = function (pathItems, hex){

    var rgb = hexToRgb(hex);

    alert(rgb.r +","+rgb.g+","+rgb.b);

    fillRGBColor(pathItems, rgb.r, rgb.g, rgb.b);

}

 

// check if a document is open in Illustrator.

if( app.documents.length > 0)

{

          mySelection = app.activeDocument.selection;

 

          if (mySelection.length > 0)  {

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

                  var currentObject = mySelection[i]; 

                  if(currentObject.typename != "CompoundPathItem" &&  

                                                            currentObject.typename != "GroupItem")  {

                     

                         fillHexColor(currentObject, '#8F623B');

                                             }

                              }

          } else {

                         alert("Nothing is selected.");

          }

 

} else {

          alert("No document Open.");

}


Split Text into Layers

$
0
0

I was wondering if anyone is aware of a script that is able to do the same as this photoshop one http://www.agasyanc.ru/text-splitter, I would use that one in photoshop but its not working in CS6.

 

I  was hoping to find a script that will seperate the text into layers  ready for export to After Effects to be used in Kinetic Typography  pieces

 

thank you

Insert superscript 2 in text field Illustrator Javascript scripting

$
0
0

Dear All,

 

I've been trying to add and remove certain pieces of text based on their font and whenever I need to add a certain piece of text back into it's original place again I need to insert a superscript 2 after this text.

This is the piece of code in which I add the text back in again:

 

if (textGroupItem.textRange.characterAttributes.textFont.toString().toLowerCase().match(regP attern)){

                textGroupItem.textRange.characters.removeAll()

                textGroupItem.textRange.characters.add(un + " - " + sm + "m" + "²")

}

This doens't give a superscript 2 but some kind of broken token as text.

 

So far i've also tried:

- translatePlaceholderText("c2b2")

- "2".sup()

-  <sup> 2</sup>

- textGroupItem.textRange.characterAttributes.baselineShift = height;  <-- height = 2 but this shifts the whole text item

 

 

How can you succesfully add a supercript 2 to a group of characters?

You can do this through a script?

$
0
0

001.gif

1. Select anchor

2. Set x position for all selected anchor

???

The initial value of mValueTX and mValueTY

$
0
0

Hello.

 

Does the initial values of mValueTX and mValueTY of the object just generated refer the upper left coordinates of the document's largest area? For example, TextFrameItem and PlacedItem.

I want to get the coordinates of the document's largest area easily. Do you have any sugesstions?

 

I referred to here.

How to get bounds of largest possible document area?

 

This script worked fine on Illustrator CS6, CC2015, CC2017, CC2018 (for mac).

Is this correct?

function getLargestBounds() {    var tempLayer,        tempText,        left,        top,        LARGEST_SIZE = 16383;    if (!app.documents.length) {        return;    }    tempLayer = app.activeDocument.layers.add();    tempText = tempLayer.textFrames.add();    left = tempText.matrix.mValueTX;    top = tempText.matrix.mValueTY;    tempLayer.remove();    return new Rect(        left,        top,        left + LARGEST_SIZE,        top + LARGEST_SIZE    );
}

var rect = getLargestBounds();
// cover the whole area.
app.activeDocument.pathItems.rectangle(rect[1], rect[0], 16383, 16383);

How to import .eps file properly into artboard without losing vector mesh

$
0
0

Hi all,

 

I've script that imports eps files in folder to the artboards. EPS file contains few rectangles and meshed photo. When I use createFromFile to import eps files,  got the result that there is no mesh in new artboard. How can I import eps file without losing mesh in it ?

Viewing all 12845 articles
Browse latest View live


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