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

Is it possible to set xmp metadata to pageItems?

$
0
0

Hi All,

 

Is it possible to set xmp metadata to pageItems?

Like there is a way in photoshop to set xmp metadata to layers.


Thanks


Changing text and keeping the font style the same

$
0
0

Using Illustrator cs 5 / JavaScript

 

I'm having a problem with keeping text styles like bold and Regular(not bold) from change.

here is the problem

say you want to change text like

Scripting is not fun! to Scripting is fun!

no problem...

var docRef = app.activeDocument;

var textRef1 = docRef.textFrames[0];

textRef1.contents = "Scripting is fun!";

 

but what if that text is like this

 

Scripting is not fun! (with "Scripting" bold and the rest regular)

when you run the same script it makes all the text bold

Scripting is not fun! = Scripting is fun!

or if "Scripting" is regular and the rest is bold it will turn all of it regular.

Scripting is not fun! = Scripting is fun!


How would we keep the styles from changing?

any help would be appreciated.

How to log the ExtendScript Tool Kit console prints to a Text File

$
0
0

Hi Chaps,

 

I want to put prints in my whole Script and take the logs of the script.

To do this I need to log the entire console output to a Text file.


Can somebody please tell me how to write the console output to a log file?

app.activeDocument.activeDataset.name

$
0
0

Hi,

 

I've set up an action that I'm using to batch my process. I iterate through the dataSets[i] that have unique names. I am trying to determine the name of the current index of the datasets[i]. I am able to read the name like this:

 

alert(app.activeDocument.dataSets[0].name);// this only reads the name of the dataset at [0] for every iteration. myset_0,myset_0,myset_0,myset_0,myset_0,myset_0,myset_0...

 

The problem is that I call this during the batch process using the dataset. I can't remove the dataset at zero, because it will change the length and mess up the batch.

 

 

I would like to do it like this:

 

alert(app.activeDocument.activeDataset.name);//myset_0,myset_1,myset_2,myset_3,myset_4,mys et_5,myset_6...

 

but I'm getting undefined.

 

I'm not sure what is wrong with the syntax of this:

 

app.activeDocument.activeDataset.name

 

thanks,

Aubrey

A Zoom_to script

$
0
0

With a lot of help from Jongware, here's a little script to change the view zoom level for an AI document window.

 

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

 

var ZF = prompt ("Enter the zoom factor you wish to use, 1.00 = 100%", 1.00, "Zoom to New Level");

 

if ( app.documents.length > 0 ) {
app.documents[0].views[0].zoom = ZF;
}

 

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

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

VB.net scaling / Resize and export as SVG

$
0
0

Hi,

 

I'm using Illustrator CS4 and VB.NET 2008.

 

I'm doing a fairly simple operation in VB.net using Illustrator.  I load an  .AI file that was saved out of Illustrator and then resave it as a SVG file.  This works fine.

 

I need to scale up the SVG since for whatever reason the SVG artwork is smaller than the AI file.    This happens even if you just save the SVG file straight out of CS2/CS3/CS4/CS5 not using any automation.  Must be a feature, not a bug.

 

Anyway, I am able to set the scalematrix but for whatever reason, when I try to apply it, I can't get the syntax or object reference right.

 

I've looked at the illustrator CS4 Scripting reference(see below) and it says " artItem.Transform totalMatrix".  If I use that syntax  VB.net complains that the "Method arguments must be enclosed in parethesis"

 

If I enclose it,Like this: artitem.Transform(scalematrix)

 

I get this Warning     "Variable 'artitem' is used before it has been assigned a value. A null reference exception could result at runtime. "  and of course, at run time it barfs with a null exception.

 

Any suggestions?  I've dug through the illustrator objects trying to see if I've defined artitem wrong or something.  I'm stuck.

 

Thanks,

 

Mark


 

---------

 

      Dim illusapp As New Illustrator.Application
      Dim illusdoc As Illustrator.Document
      Dim scalematrix As Illustrator.Matrix
      Dim artitem As Illustrator.PathItem
      illusapp.UserInteractionLevel = Illustrator.AiUserInteractionLevel.aiDontDisplayAlerts
      
      Dim svgOpt = new illustrator.ExportOptionsSVG
      svgOpt.DTD = Illustrator.AiSVGDTDVersion.aiSVG1_0   

 

            illusdoc = illusapp.Open("c:\test\test.ai")

 

            scalematrix = illusapp.GetScaleMatrix(125,125)

'------ Problem starts here.

            artitem.transform(totalmatrix)
'------ Problem ends here.

 

            illusdoc.Export("c:\test\test.svg",Illustrator.AiExportType.aiSVG,svgopt)
            illusdoc.Close

 

-------

From Adobe Illustrator CS4 Scripting Reference.

     Applying transformations with a matrix
'Creates a new translation and rotation matrix then
'applies it to all items in the current document


Set appRef = CreateObject("Illustrator.Application")

 

'Move art half an inch to the right and 1.5 inch up on the page

 

     Set moveMatrix = appRef.GetTranslationMatrix(72 * 0.5, 72 * 1.5)

 

'Add a rotation to the translation -- 10 degrees counterclockwise

 

     Set totalMatrix = appRef.ConcatenateRotationMatrix(moveMatrix, 10)

 

'Apply the transformation to all art in the document

 

For Each artItem In appRef.ActiveDocument.PageItems
     artItem.Transform totalMatrix
Next

Cutting a circle

$
0
0

Hi all,

 

I need to make shapes like this based on a value for graph purposes - usually I would just create a cutting shape based on trig (this shape representing around 60%) and subtract it from the path - I have about 30 graphs to do and I need to base it on a variable, and I want to use script - I'm sure there must be a better way, and I'm hoping you guys have the answer.

 

Thanks in advance

 

Dave

cut.png


Export multiple ARTBOARDS to multiple JPGs (AppleScript)

$
0
0

I´m aware that Illustrator doesn´t have multiple artboards options for JPG as it does with eps, or other formats, but is there any workaround for this??

Looping current artboard and exporting them to JPG or something. 

Or maybe there is someway to force the   "save multiple artboards:true" in JPG??

 

 

exportdocumentcurrentDoctofileexportFolderasJPEGwith options¬

                                                  {class:JPEG export options¬

                                                            , quality:100 ¬

                                                            , artboard clipping:true¬

                                                            , artboard range:1 - 2 ¬

                                                            , save multiple artboards:true}

Script for Selecting Open Paths in Illustrator CS6

$
0
0

I have created this script for selecting open paths in illustrator cs6 as the graffix plugin is not working under CS6.

 

Just save the following text in /Applications/Adobe Illustrator CS6/Presets/en_US/Scripts/Select Open Paths.js

 

 

if (documents.length > 0 && activeDocument.pathItems.length > 0){
 
          var allPaths = activeDocument.pathItems;
          var allPathsCount = allPaths.length;
          var openPathsAreLocked = false;
          var lockedOpenPaths = 0;
          var locked = false;
          for (var i=0; i < allPathsCount; i++){
                    allPaths[ i ].selected = false;
 
                    if( ! allPaths[ i ].closed){
 
                              try{
                                        allPaths[ i ].selected = true;
                              } catch (e) {
                                        openPathsAreLocked = true;
                                        lockedOpenPaths++;
                              }
 
                    }
          }
          if (openPathsAreLocked) alert (lockedOpenPaths + " open paths are locked or hidden (or their layer is locked or hidden) and cannot be selected");
}

Create Fitted Artboards from layers?

$
0
0

Hey everyone,

 

Does anyone know of a script that will create artboards for each separate layer?

 

Thanks in advance,

 

Andy

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

)

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

Select an object in illustrator using extendscript

$
0
0

I have a drawn rectangle on an illustrator document. In the layers menu I have given it a specific path name (outerBox). I would like to select this item and return its particular properties eg height, width, colour etc. How would I do this.

 

Thanks

Bob

Appending metadata to a file

$
0
0

Hi,

 

I found this script to write XMP metadata to an open file, but it does not seem to work for me in Illustrator CC. The error message is "XMP exception: Source and destination XMP must differ".

Is there perhaps an alternative method of writing properties to the XMP fields?

 

Thanks,

Rich

 

 

if( xmpLib == undefined ) {

var xmpLib = new ExternalObject("lib:../../Frameworks/AdobeXMPScript");

app.synchronousMode = true;

}

 

var docXmp = new XMPMeta(app.activeDocument.XMPString);

var myXmp = docXmp;

myXmp.setProperty(XMPConst.NS_XMP, "CreatorTool", "My Script");

 

XMPUtils.appendProperties(myXmp, docXmp, XMPConst.APPEND_ALL_PROPERTIES);

var myDocFile = new File(app.activeDocument.fullName);

var docRef = new XMPFile(myDocFile.fsName, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_UPDATE);

if (docRef.canPutXMP(docXmp)) { docRef.putXMP(docXmp); }

docRef.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);


ExtendScript try/catch difference when script ran from ESTK and Illustrator

$
0
0

Hello,

 

I've written an ExtendScript for Illustrator using the ExtendScript ToolKit (ESTK).  This scripts works really well when running it in Illustrator from the ESTK (using the target application functionality).

 

However when I run it directly within Illustrator (by selecting it from the dropdown File > Scripts) I get a run time error.  Is this normal?  Should I expect differences when running the script in these two different ways?

 

The error is in this function...

 

```

function itemUsable (arr, item) {

    var usable = true;

    try {

        arr[item];

        usable = true;

    } catch(e) {

        $.global.alert(e);

        usable = false;

    }

    return usable;

}

```

 

The point of the code is to get around Illustrator's issue of throwing errors when accessing properties that don't always exist.  Ran from ESTK the try/catch statement catches the error "No such element" and then sets the function to return false.

 

When ran directly from Illustrator the error message fires but the try/catch doesn't seem to stop the script from exiting.

 

The only difference I can see is when running the script from ESTK the dropdown menu next to the application target dropdown is always (and has only the option) "main".  Running the script directly from Illustrator, when the error is thrown this dropdown option is set to the value "transient".

 

See this screenshot for an example what I mean

 

Screen Shot 2015-04-16 at 20.16.32.png

 

Any help would be much appreciated.

 

Thanks,

/t

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

Batch replace color without using swatch as source

$
0
0

I've searched these forums and the rest of the web trying to find a method to do this... Actions don't cut it (if Actions were able to record the "replace color" dialoge it would be fine) so I've turned to scripts, but I have almost no knowlege on this.

 

I checked out this thread:

http://forums.adobe.com/message/2588737

 

and it is very close, except that it assumes that there is a named swatch as the source color - which there isn't.

 

The script I tried was .JS

 

I'm trying to have the script run on a bunch of .eps files in a folder:

- Select object which has specified CMYK value (0,7,34,10)

- Replace fill color of the selected object with another CMYK value (5,19,36,0)

- Save over the existing .eps

- Close

- Make coffee (optional)

 

Also, any books you can recommend for learning this stuff? For a noob.

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

fill color using a script.

$
0
0

I'm trying to create a script in CS5 mac os10.6.8 that will change the fill color of selected pathItems. I need a simple script that will change a selected pathItem to cmyk values 2,3,15,0. I will then select this script and implement the action in a batch of 600 files.

 

I wish this process could be recorded as an action but when I record the action "add new swatch" I have to manually input the cmyk values, which will take forever for a batch of over 600 files.

Viewing all 12845 articles
Browse latest View live


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