Quantcast
Channel: Adobe Community : Discussion List - Illustrator Scripting
Viewing all 3671 articles
Browse latest View live

Javscript: Using JSON files on disk

$
0
0

Hi,

Adobe CC 2013, not 2014.

I normally work in other languages so my Javascript knowledge is newly budding.

 

I have JSON files that I've generated from another program that I need to be read into Illustrator and I've gotten everything in the script to work -  however, it appears that to use JSON.parse or $.getJSON, I need to use Node.js (because of the require() function and the filesystem('fs') functions) which wasn't implemented until the CE5 Extension that came out this summer for CC2014.  However, at work, we're on CC2013 and I don't believe that we're due for an upgrade.

 

Am I correct in this or does somebody have some awesome news for me?

Or even an alternative would be great!

 

Thanks.


Javascript to make selection of top level group?

$
0
0

Does anyone know of a way to select a top level group by index?

 

For example, i have many files with deeply nested groups and i want to select all artwork in only the top level groups and create an artboard around the visible bounds of said group.

 

I've been able to loop through the groupItems of the document, but i cannot seem to differentiate between top level groups and sub groups. In other words, the loop is working properly, but it is creating an artboard around the top level group, then around each subgroup and each group within that subgroup.

 

In the attached image, you can see that there are 5 top level groups in this document. However, basically everything else is grouped within those groups. for example, the "YouWho" logo is approximately 100+ path items grouped together. the information on the collar is grouped several times in a complex hierarchy as well.

 

The obvious solution is to ungroup everything and then regroup each shirt piece as 1 group. unfortunately, that in itself is more time consuming than manually creating the artboards and then the file is not very clean if we ever need to get back inside it to change/fix something.

 

i'm imagining some way to loop through the subgroups and ignore them if they are within the geometric bounds of the top level?? But i'm not really sure where to start on that code..

 

This is the code i have currently that is creating artboards around each groupItem, but also around each groupItem within the top level... it also throws an error because i think illustrator can't keep up with creating the artboards that fast? when i run the same script on less complicated artwork it works fine.

 

var docRef = app.activeDocument;
var aB = docRef.artboards;
var gI = docRef.groupItems;


for (a = 0; a< gI.length; a++){    var currentGroup = gI[a];    currentGroup.selected = true;    var vB = currentGroup.visibleBounds;    aB.add(vB);//an Illustrator error occurred: 1346458189 ('MRAP')
}  

 

any ideas how to isolate that top level group and ignore the rest?? Thanks folks.

 

Screen Shot 2015-01-05 at 11.06.17 AM.jpg

Transform all the Objects

$
0
0

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

 

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

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

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

Giving Opacity the same value as fill color (Inverting Opacity/Fill)

$
0
0

I am looking to add a script that would take the fill value of swatches in my art file, and apply those values to the opacity of each swatch.  I would also like to be able to adjust the fill value to be 100% when finished.  I have a javascript that I thought would work, but it has no effect on any of the objects in the file.

 

Example:

Original Art: Object 1: Fill 50%, Opacity 100% // Object 2: Fill 60%, Opacity 100%

Desired Result: Object 1: Fill 100%, Opacity 50% // Object 2: Fill 100%, Opacity 60%

 

Any help would be much appreciated.

VBS - selecting loaded Dataset

$
0
0

Hello Everyone,

 

I been long time reader of this forum, you guys are great.

 

I created a little script that loads Dataset in to a chart, but I have to go then and manually pick the Datset from drop down menu.

 

Is there a simple command to set DATASET to XXXX and refresh chart in VBS ?

 

All the help is appreciated.


Javascript to determine named fill/stroke color of pathItem[index]?

$
0
0

I'm attempting to build a preflight of sorts for my Illustrator workflow (since for some reason.. preflight in illustrator doesn't exist...).

 

Essentially i need to loop through the pathItems on each artboard looking for a specific spot color (first verifying that the spot color does NOT exist as a fill color in any of the artwork, then checking for the presence of any pathItem that contains the spot color as a stroke).

 

This seemed to be a really straightforward task, but it seems as though pathItems.fillColor or pathItems.strokeColor is not a valid property? That confuses me because it works to apply a color to a pathItem.. It seems to me if you can apply a color via pathItems.fillColor, you should also be able to create an if clause that determines whether pathItems.fillColor == (some color). However, while testing this in the simplest of documents wherein i know what the result of the if clause should be, it doesn't work. is there something I'm missing here about the property fillColor/strokeColor??

 

Here's the code I'm working with. Thanks, all.

 

#target Illustrator




var docRef = app.activeDocument;
var aB = docRef.artboards;
var swatchList = docRef.swatches;
var tC = swatchList.getByName("Thru-cut");
var tCCount = 0; //how many artboards/top level groups contain at least 1 Thru-cut stroke?
var artLayers = docRef.layers;
var groups = artLayers[0].groupItems;
var aBtCCount = 0; // how many artboards have
var aBnoTC = []; //  which artboards/top level groups (by index) do not contain at least 1 Thru-cut stroke?


for (a = 0; a < aB.length; a++){    aBtCCount = 0    var items = groups[a].pathItems;    for (b = 0; b < items.length; b ++){        if (items[b].fillColor == swatchList.getByName("Thru-cut")){            alert("You have Thru-cut fills in your document!!");            break;            } //end if // thru-cut is fill        else if (items[b].strokeColor == swatchList.getByName("Thru-cut")){            tCCount++;            break;            } //end if // thru-cut is stroke        else{            tCCount = 0;            } //end else // set counter to 0        }//end for loop B // checking items on each artboard    if(tCCount == 0){        aBnoTC.push(" " + a);        }//end if // artboard has no cut line    else{        aBtCCount++;        }//end else // add to counter for total artboards w/ thru-cut    alert(tCCount);           }//end for loop A


if (aBtCCount < aB.length){    alert("Artboard/s " + aBnoTC + " are missing Thru-cut lines");    }//end if // not enough cut lines   

applescript for saving ai files to pdf with specific preset not working

$
0
0

Hello all,

my applescript for saving ai files to pdf with my specific preset (A1) not working anymore (after installing cc 2014)

it worked for years .....

I need to work in CS6 still so I have both ai's on my machine

I copied my specific PDF preset in all PDF preset folders on my sysytem

It seems that the script doesn't find my specific pdf preset anymore

Is this still a bug ?

 

I get a illustrator error report 1129270854 ('FNOC')

 

The script:

-- fileList is a list of aliases to Illustrator files

-- destFolder is an alias to a folder where PDF files are saved

on SaveFilesAsPDF(fileList, destFolder)

    set destPath to destFolder as Unicode text

    repeat with aFile in fileList

        tell application "Finder" to set fileName to name of aFile

        set newFilePath to destPath & fileName

        tell application "Adobe Illustrator"

            open aFile

            save current document in file newFilePath as pdf with options {class:PDF save options, PDF preset:"A1"}

            close current document saving no

        end tell

    end repeat

end SaveFilesAsPDF

-- Call handler

set sourceFolder to choose folder with prompt "Source folder?"

tell application "Finder" to set fileList to every file of folder sourceFolder as alias list

set destFolder to choose folder with prompt "Destination folder?"

SaveFilesAsPDF(fileList, destFolder)

 

Why is it not working anymore, anyone?

thank you

pat

How convert Matrix to Rotate?

$
0
0

Example:

Value of Matrix of TextFrame:

MValueA=0.707110047340393

MValueB=0.707110047340393

MValueC=-0.707110047340393

MValueD=0.707110047340393

MValueTX=-11116.84375

MValueTY=-281.0703125

How convert Matrix to Rotate?

exportFile results in 'undefined' in Illustrator CC 2014

$
0
0

Hello-

 

I am creating a script to help version my files. the intended goal is to export the active document to a child directory as a PNG.  I have followed the CC 2014 scripting examples but the 'exportFile' method is returning undefined.   Also in the Object viewer that method is not returned on search.  I am trying to ascertain  if that method has been deprecated in this latest release.  I do not have experience with prior versions of Illustrator so I am not aware if how this functioned in past.

 

Has anyone had success with this method in CC 2014?  Any Clarity lent would be appreciated.

 

Brian in NYC

 

var watchfolder = "/watchFolder";

 

exportPNGWithTimestamp (watchfolder);

 

function exportPNGWithTimestamp (watchfolder){

var date = new Date;

var month = date.getMonth() +1; //for zero index

var day = date.getDate();

var time = date.toLocaleTimeString();

var type = ExportType.PNG24;

var fileSpec= new File(watchfolder + "/" + app.activeDocument.name + "_" + month + "_" + day + "_" + time + ".png");

app.activeDocument.exportFile (fileSpec, type);  

    }

How get rotate of TextFrame?

$
0
0

I have a TextFrame : Rotate 45 ange

I want to get Rotate of this TextFrame and set to new TextFrame Add

I find in document, only exist function set Rotate to TextFrame.

How get rotate of TextFrame?

Looking for "Replace with Symbol" script

$
0
0

So I am trying to replace gps points with a symbol I have created. I have found blogs referencing a script that can replace selected items with symbols saved in the symbols panel, but I can't seem to find the actual script! If anyone knows where I can find JET_ReplaceWithSymbol.jsx or any other script that can do the same function, it would be greatly appreciated!

How reset the rotation of a PageItem (or access it's matrix at least) ?

$
0
0

I'd like to apply rotation to a few PageItem instances, but would like to reset the rotation first so it doesn't accumulate when I run the same script multiple times. I'm having a hard time trying to figure out how to restet the transformation matrix.

 

I've spotted this post which is close to what I need but it's a bit old now.

It looks like there isn't a matrix property anymore.

This:

 

alert(app.activeDocument.selection[0].matrix);

ouputs undefined

 

I've tried

 

app.activeDocument.selection[0].transform(app.getIdentityMatrix());

but it seems transformations are accumulated, multiplied, not reset.

 

If I want to reset the rotation of a PageItem, how would I go about doing that ?

 

Thanks,

George


Rotating text around a circle. Have selected Warp options selected arch but text doesn't appear right?

$
0
0

Using Mac Pro. Have created a vector logo. All good so far. Trying to add text to a round circle shape have got as far as selecting Warp option and typed my text but despite adjusting the scale etc it doesn't seem to look right as it isn't snapping to the circle. I have tried dragging the anchors but that makes it worse!!

Applying/Editing Fill and Opacity Values to Gradients?

$
0
0

Running off of previously answered question here.

 

Trying to see what I would have to call to adjust values of each stop in a gradient, specifically the fill.tint and opacity values.  I would like to apply the following script to the fills.

 

var docRef = app.activeDocument; 
var paths = docRef.pathItems;   
for (i=0; i< paths.length; i++){     if (paths[i].fillColor.tint == 50 && paths[i].opacity == 100){         paths[i].fillColor.tint = 100;         paths[i].opacity = 50;                  }     else if (paths[i].fillColor.tint == 100 && paths[i].opacity == 50){         paths[i].fillColor.tint = 50;         paths[i].opacity = 100;                 }     }

 

 

Here is one of the test files I'm using.   In this file looking to make white stops (Fill of 0) have an opacity of 0, and stops of magenta have an opacity equal to their fill.

 

Any assistance would be much appreciated.  Thank you!

Calling for objects with specific CMYK values?

$
0
0

Hello,

 

I'm trying to build a script that searches for paths that have specific CMYK values within a document and then edits the opacity of that path. I can specify for it to look only for objects that have a CMYK color but get nothing once I try to specify the CMYK values I'm looking for.

 

Additionally, do I need to specify that the output will be a "new CMYKColor", or will it suffice to say "paths[i].fillColor.back = 100.0", for example, in the output. Here's what I have for this particular function:

 

var docRef = app.activeDocument;
var paths = docRef.pathItems;

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

if (paths[i].fillColor.typename == "CMYKColor" ) {

if (paths[i].fillColor.cyan == 0.0 &&
paths[i].fillColor.magenta == 0.0 &&
 paths[i].fillColor.yellow == 0.0 &&
 paths[i].fillColor.black == 20.0 &&
 paths[i].opacity == 100.0) {

var NewColor = new CMYKColor ();

NewColor.cyan = 0.0;
NewColor.magenta = 0.0;
NewColor.yellow = 0.0;
NewColor.black = 100.0;
paths[i].opacity = 20;
}

else {
alert ("Object(s) not recognized.")
}

}
else {
alert ("Object not CMYK.")
}
}

 

Thank you.

How to sort objects alphabetically (inside of a layer)?

$
0
0

How to sort objects alphabetically (inside of a layer) on layer list?

I have already tried scripts for Layer sorting. They work indeed for the layers, but not the objects themselves packed inside.

Scripts that interact with other applications, such as Excel

$
0
0

Hello Everyone,

 

This is from the Illustrator CS6 Scripting guide.

 

"A script is a series of commands that tells Illustrator to perform one or more tasks. These tasks can be

simple, affecting only one object in the current document, or complex, affecting objects in all your

Illustrator documents. The tasks might even involve other applications, like word processors, spreadsheets,

and database management programs."

 

I have been trying to find a starting point to figure out how to do this, but I have not found any examples online. Is their any resources out there that anyone knows of? One of the things I am trying to do for example, is to copy a specific column from an excel document and pasting it into illustrator. Thanks in advance!

Viewing all 3671 articles
Browse latest View live


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