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

Creating Multiple Artboards

$
0
0

I thought I'd ask this question here seeing as how everything I've learned about scripting has come from the knowledge everyone shares here (granted, I've only been at this a couple weeks now).

 

I've searched and searched and have been trying for three days to figure this out but can't.  I've studied the scripts at http://forums.adobe.com/message/5082308#5082308 and tried implementing them but to no avail.

 

Basically, I have a document with multiple layers, all containing only one item each.  Every placedItem is a tiff, all having the same dimensions.  There could be either 4 or 6 of them, no more, no less.  I'd like to split them up onto multiple artboards but whenever I try, I keep getting multiple boards put in the same location, e.g., stacked on top of one another.  I can't seem to figure out the gridByRow command.

 

So far, I'm using the following script (that I found here) to build the file, which I've altered to fit my needs.

 

 

function getFolder() {          return Folder.selectDialog('Please select the folder to be imported:', Folder('~'));
}


function importFolderAsLayers(selectedFolder) {
          // if a folder was selected continue with action, otherwise quit          var myDocument;          if (selectedFolder) {                    myDocument = app.documents.add();                    var firstImageLayer = true;                    var newLayer ;                    var thisPlacedItem;                    // create document list from files in selected folder                    var imageList = selectedFolder.getFiles();                    for (var i = 0; i < imageList.length; i++) {                              // open each document in file list                              if (imageList[i] instanceof File) {                                        // get the file name                                        var fName = imageList[i].name;                                        // check for supported file formats                                        //if( (fName.indexOf(".eps") == -1) ) {                                        if( (fName.indexOf("Base.tif") == -1) && (fName.indexOf("White.tif") == -1) && (fName.indexOf("Process%20Yellow.tif") == -1) && (fName.indexOf("Process%20Cyan.tif") == -1) && (fName.indexOf("Process%20Magenta.tif") == -1) && (fName.indexOf("Process%20Black.tif") == -1)) {                                                  // skip unsupported formats                                                  continue;                                        } else {                                                  if( firstImageLayer ) {                                                            newLayer = myDocument.layers[0];                                                            firstImageLayer = false;                                                  } else {                                                            newLayer = myDocument.layers.add();                                                  }                                           // Give the layer the name of the image file                                           newLayer.name = fName.substring(0, fName.indexOf(".") );                                           // Place the image on the artboard                                           thisPlacedItem = newLayer.placedItems.add()                                           thisPlacedItem.file = imageList[i];                                        }                              }                    }

 

What I'd like to do at this point is spread these layers out to multiple artboards, which have been made based on the number of layers in the file.

 

3 days!  I'm pulling my hair out.  Can someone help?  Using CS5.


Tweaking the SaveDocsAsPDF script

$
0
0
Hello. Absolute scripting newbie here; will someone take pity...?

I am looking at the SaveDocsAsPDF script. It works for our purposes except I would like it to save PDFs using a Preset we created called "SGS PDFs. (We have trouble with people in our office forgetting to choose this setting, so I thought a script might be the answer.)

I found a posting on this forum where someone wanted to save files as small as possible, and got some clues from that. So I left everything as is in the original script, except I added this first line in the function:
{var NamePreset = '[SGS PDFs]';

Then after the line:
var options = new PDFSaveOptions();

I added:
options.PDFPreset=NamePreset;

I thought this would result in a script that does the same thing I now do "manually". However, if I save my document "manually" using File/Save As/ Adobe PDF, and choosing the SGS PDFs preset (and changing nothing else), I get a 716 KB file. But if I use my script, I get a 4.9 MB file. So it appears that what I added is NOT making the script use my preset settings.

So my question is: Is there something REALLY basic missing from my script, or... In order to get a script that accomplishes everything already determined in the Preset, do I manually have to list all those settings as options?

I think I can do the latter if I need to if I just study some of the other scripts... unless there's a shortcut!

Can I get more sizing information in scripted JPEG exports?

$
0
0

Exporting to JPEG from script seems to give less size/resolution information than exporting from AI itself.

 

This manifests itself when opening in Microsoft Word, when the 'from AI' JPEG appears correctly sized, whereas the 'from script' JPEG just fills whatever page size you've specified.

 

Does the 'from AI' JPEG have more metadata compared to the 'from script' JPEG? This is what it looks like when I look at the files using Exiftool.

 

Does 'from AI' have EXIF data, maybe as well as JFIF? Does 'from script' only have JFIF? And Word is only looking at the EXIF data?

 

Can I get EXIF into the exports?

 

Thanks

Anti-aliasing Type Optimized/Art Optimized on PNG export

$
0
0

Hello there,

 

I'm modifying a javascript that makes an export of each layer contained in an Illustrator document and I want to specify the method used for anti-aliasing (either Type Optimized or Art Optimized). Similarly to the option under the "Image size" tab in the "Save for the Web" panel.

 

I didn't find any antiAliasingMethod property in the ExportOptionsPNG24 properties (only an antiAliasing property that accepts boolean). So I wonder if it is actually possible to do it through scripting?

 

Many thanks,

D

Batch insert filename in textpath script crashes Illustrator

$
0
0

Hi everyone!

First off: I am not a programmer. Just playing around with code and trying to get it to work for a specific task:

 

Here is a script made for the purpose of inserting a text with the file name in over 600 pdf files. This is suppose to work on all files in a selected folder.

 

The problem: Illustrator crashes.

 

A first test code worked but after a few edited files Illustrator crashed, so I tried to introduce a delay after each save in order to slow down the batch process.

$.setTimeout(function () {sourceDoc.close(SaveOptions.SAVECHANGES)}, 1000);

Unfortunately I did not save the working (almost working ) first test code.

 

No idea what to do next. The code works if I delete this line: sourceDoc.close(SaveOptions.SAVECHANGES);

 

Here is the complete script:

 

var destFolder, sourceFolder, files, fileType, sourceDoc, layers, writeText, finLabel;

// Select the source folder.
sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to PNG', '~' );

// If a valid folder is selected
if ( sourceFolder != null )
{
files = new Array();
fileType = prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', '*.pdf' );

// Get all files matching the pattern
files = sourceFolder.getFiles( fileType );

if ( files.length > 0 )
for ( i = 0; i < files.length; i++ )
{    sourceDoc = app.open(files[i]); // returns the document object    layers = unlock();    writeText = getFilename();    finLabel = remText();    sourceDoc.close(SaveOptions.SAVECHANGES);   //if save command line is deleted the code works   WTF???    $.setTimeout(function () {sourceDoc.close(SaveOptions.SAVECHANGES)}, 1000); // still crashes using delay ...
}
//alert( 'Files are saved as PNG in ' + destFolder );

else
{
alert( 'No matching files found' );
}
}

function unlock()
{
   //get the total number of layers in the active document
doc = app.activeDocument;
var totalLayers = doc.layers.length;

//looping on layers to create one artboard per layer
for ( var i = 0 ; i < totalLayers ; i++){       var currentLayer = doc.layers[i];       //We don't want to deal with hidden layers    if(currentLayer.visible == false) continue;       //Unlock the layer if needed    currentLayer.locked = false;

}
    }

function getFilename()
{
// Write text
var pointTextRef = app.activeDocument.textFrames.add();
pointTextRef.contents = app.activeDocument.name + "\n" + "YBS";
pointTextRef.top = 0;
pointTextRef.left = 0;
app.activeDocument.textFrames[0].textRange.characterAttributes.textFont=app.textFonts[31];
       }

function remText()
{
// This works for search and replace :))))))

    var active_doc = app.activeDocument;          var search_string = /_Template.pdf/gi; // g for global search, remove i to make a case sensitive search     var replace_string = '';          var text_frames = active_doc.textFrames;          if (text_frames.length > 0)     {         for (var i = 0 ; i < text_frames.length; i++)           {               var this_text_frame = text_frames[i];                var new_string = this_text_frame.contents.replace(search_string, replace_string);                                if (new_string != this_text_frame.contents)                    {                         this_text_frame.contents = new_string;                    }           }     }     
 }

 

Any ideas about what makes Illustrator crash?

Note: The application crashes after opening the first file.

Thanks for helping out!

Copy item style attributes/properties to other item?

$
0
0

Just want to ask if someone know if there is short way to copy item properties to other object, than go through every possibilities with script. There is quite many possibilities with strokes and so on, so this could be helpful...

I mean like with "Eyedropper Tool", but with the script

 

I can set them manually like below. But just want to know is there already some "shortcut" way to handle this kind object style copying?

 

var doc = app.activeDocument;
var selectedItems = doc.selection;

var newLayer = doc.layers.add();
var ellipse = newLayer.pathItems.ellipse(100, 0, 100.0, 100.0, false, true );

ellipse.fillColor = selectedItems[0].fillColor;
ellipse.strokeColor = selectedItems[0].strokeColor;
ellipse.strokeWidth = selectedItems[0].strokeWidth;
ellipse.strokeDashes = selectedItems[0].strokeDashes;
ellipse.strokeDashOffset = selectedItems[0].strokeDashOffset;
// etc etc...

Building a color chipper

$
0
0

I'm new to scripting was handed a tool that pulled ink sport colors and made chips and have been saddled with a hard task, and need some help.

 

I need to create a tool wich will;

  • look at a file with multiple pieces of artwork on multiple layers,
  • create one color chip for each of the fill colors of the objects on each layer without repeating a chip,
  • generate a text field next to the chip that pulls the name of the fill color for the chip from the swatches pallet,
  • then align the chips for each layer to the artwork on that layer so they make nice neat columns below the artwork.

 

I have been able to creat something that looks at the swatch pallet and generates color chips for each swatch, and then name them the swatch name but I'm having trouble with aligning them, having it run once for each layer, and limiting the chips created to only one per fill color of objects.

 

This is the working script I have made.

 

 

function chipperMod()
{
    this.windowRef = null;
}

 

chipperMod.prototype.run=function()
{

 

    var docRef=app.activeDocument;
    var swatchXAnchor=646;
    var swatchYAnchor=42;
   
    var win = new Window("dialog", "Chipper Mod", [200, 200, 380, 395]);
    this.windowRef=win;
   
    win.scmPanel=win.add("panel", [10, 10, 170, 150], "Template Size");
   
    win.scmPanel.ltrPort=win.scmPanel.add("radiobutton", [10, 10, 180, 30], "Letter - Portrait");
    win.scmPanel.ltrLand=win.scmPanel.add("radiobutton", [10, 40, 180, 60], "Letter - Landscape");
    win.scmPanel.tabPort=win.scmPanel.add("radiobutton", [10, 70, 180, 90], "Tabloid - Portrait");
    win.scmPanel.tabLand=win.scmPanel.add("radiobutton", [10, 100, 180, 120], "Tabloid - Landscape");
       
    win.scmPanel.tabLand.value=true; //automaticly checks tabloid
   
    win.scmPanel.ltrPort.onClick=win.scmPanel.ltrLand.onClick=win.scmPanel.tabPort.onClick=wi n.scmPanel.tabLand.onClick = function()
    {
        if(win.scmPanel.ltrPort.value)
        {
            swatchXAnchor=35;
            swatchYAnchor=72;
        }
        else if(win.scmPanel.ltrLand.value)
        {
            swatchXAnchor=35;
            swatchYAnchor=72;
        }
        else if(win.scmPanel.tabPort.value)
        {
            swatchXAnchor=35;
            swatchYAnchor=77;
        }
        else if(win.scmPanel.tabLand.value)
        {
            swatchXAnchor=646;
            swatchYAnchor=42;
        }
    }

 

    win.goBtn = win.add("button", [10, 160, 80, 175], "Chip It");
    win.goBtn.selected = true;
    win.noBtn = win.add("button", [100, 160, 170, 175], "Cancel");
   
    win.goBtn.onClick = function ()
    {
    for(i=docRef.swatches.length-1;i>=0;i--) // for i variable = # of inks used ; list length greater then 0 ; list length decreasing
    {
        var swatchesRef=docRef.swatches[i];
        var swatchesRefName=swatchesRef.name;
   
            var swatchGroup=docRef.groupItems.add();                     // adds a group
            var swatchBox=swatchGroup.pathItems.rectangle(swatchYAnchor, swatchXAnchor, 22, 15); // adds a 22x15 swatch at some ancor points bassed on paper chosen
            swatchBox.fillColor=docRef.swatches.getByName(swatchesRefName).color; //fills with swatch color
            swatchBox.stroked=true;
            swatchBox.strokeWidth=.5;
            swatchBox.strokeColor=new GrayColor();
            swatchBox.strokeColor.gray=50;
            var swatchLabelX= swatchBox.left+swatchBox.width+6;
            var swatchLabelY = swatchBox.top-7; //setting margins
            var swatchLabel = swatchGroup.textFrames.pointText([swatchLabelX,swatchLabelY]);
   
            swatchLabel.contents = swatchesRefName;
            swatchLabel.textRange.characterAttributes.size=8;
            swatchLabel.textRange.characterAttributes.fillColor=new GrayColor();
            swatchLabel.textRange.characterAttributes.fillColor.gray=50;
            swatchXAnchor+=(84);
       
    }//end for
    win.close();
    }

 

    win.noBtn.onClick = function ()
    {
        win.close();
    }

 

    win.show();
   
}

 

if(typeof(chipperMod_unitTest) == "undefined") // is equal to
{
    new chipperMod().run();
}

 

 

And this is how I have tryed to change it to compare the swatches to fill of path objects.

 

 

 

function chipperMod ()
{
    this.windowRef = null;
}

 

chipperMod.prototype.run=function()
{

 

    var docRef=app.activeDocument;
    var swatchXAnchor=646;
    var swatchYAnchor=42;
   
    var win = new Window("dialog", "Chipper Experiment", [200, 200, 380, 395]);
    this.windowRef=win;
   
    win.scmPanel=win.add("panel", [10, 10, 170, 150], "Template Size");
   
    win.scmPanel.ltrPort=win.scmPanel.add("radiobutton", [10, 10, 180, 30], "Letter - Portrait");
    win.scmPanel.ltrLand=win.scmPanel.add("radiobutton", [10, 40, 180, 60], "Letter - Landscape");
    win.scmPanel.tabPort=win.scmPanel.add("radiobutton", [10, 70, 180, 90], "Tabloid - Portrait");
    win.scmPanel.tabLand=win.scmPanel.add("radiobutton", [10, 100, 180, 120], "Tabloid - Landscape");
       
    win.scmPanel.tabLand.value=true; //automaticly checks tabloid
   
    win.scmPanel.ltrPort.onClick=win.scmPanel.ltrLand.onClick=win.scmPanel.tabPort.onClick=wi n.scmPanel.tabLand.onClick = function()
    {
        if(win.scmPanel.ltrPort.value)
        {
            swatchXAnchor=35;
            swatchYAnchor=72;
        }
        else if(win.scmPanel.ltrLand.value)
        {
            swatchXAnchor=35;
            swatchYAnchor=72;
        }
        else if(win.scmPanel.tabPort.value)
        {
            swatchXAnchor=35;
            swatchYAnchor=77;
        }
        else if(win.scmPanel.tabLand.value)
        {
            swatchXAnchor=646;
            swatchYAnchor=42;
        }
    }

 

    win.goBtn = win.add("button", [10, 160, 80, 175], "Chip It");
    win.goBtn.selected = true;
    win.noBtn = win.add("button", [100, 160, 170, 175], "Cancel");
   
   
    // I HATE THIS FUNCTION
    //
    //
    //
    // HATE!!!
    win.goBtn.onClick = function ()
    {
    for(i=docRef.swatches.length-1;i>=0;i--) // for i variable = # of swatches used -1; list length greater then 0 ; list length decreasing
    {
        var swatchesRef=docRef.swatches[i];
        var swatchesRefName=swatchesRef.name;
        for(ii=docRef.pathItems.length-1;ii>=0;ii--) // for ii variable = # of paths used -1; list length greater then 0 ; list length decreasing
        {
            var pathRef=docRef.pathItems[ii];
            docRef.groupItems.add();
            // problem seems to be this if
        if(docRef.swatches.getByName(swatchesRefName).color==pathRef.fillColor) // if the color of the swatch = the fill color of the path then
        {
            var swatchGroup=docRef.groupItems.add();                     // adds a group
            var swatchBox=swatchGroup.pathItems.rectangle(swatchYAnchor, swatchXAnchor, 22, 15); // adds a 22x15 swatch at some ancor points bassed on paper chosen
            swatchBox.fillColor=docRef.swatches.getByName(swatchesRefName).color; //fills with swatch color
            swatchBox.stroked=true;
            swatchBox.strokeWidth=.5;
            swatchBox.strokeColor=new GrayColor();
            swatchBox.strokeColor.gray=50;
            var swatchLabelX= swatchBox.left+swatchBox.width+6;
            var swatchLabelY = swatchBox.top-7; //setting margins
            var swatchLabel = swatchGroup.textFrames.pointText([swatchLabelX,swatchLabelY]);
   
            swatchLabel.contents = swatchesRefName;
            swatchLabel.textRange.characterAttributes.size=8;
            swatchLabel.textRange.characterAttributes.fillColor=new GrayColor();
            swatchLabel.textRange.characterAttributes.fillColor.gray=50;
            swatchXAnchor+=(84);
        }//end if
    }//end for
}
    win.close();
    }

 

    win.noBtn.onClick = function ()
    {
        win.close();
    }

 

    win.show();
   
}

 

if(typeof(chipperMod_unitTest) == "undefined") // is equal to
{
    new chipperMod().run();
}

 

Any help anyone can give me, would be much aprechiated. Maybe I have been going at this all wrong, I'm just not sure. I've tested the above and know it runs threw both of the loops and think that the problem is in  if(docRef.swatches.getByName(swatchesRefName).color==pathRef.fillColor) but even after I get that figured out I dont know how to make it not repeat making a chip unless its used on multiple layers. Or how to align them based on art in layers instead of just a place on the artboard. Thanks for reading and once again any help is apprechiated.

Illustrator script to select multiple layers

$
0
0

I have about 74 layers in illustrator and i want to run a script to select combination of layers at a time.

 

For e.g. I want 5 layers to be selected and save them as one .jpg. Then say i need to select other 3 layers to save it as a seperate .jpg file. If i do it manually it comes upto 300,000 images.

 

I can create a csv file with all layers to be selected presented in a row. I need help with the command to select 4 or more layers at a time, say if i have layer1, layer2, layer3, layer4 then a command to select those 4 layers and save them as a .jpg file.

 

Any help will be greatly appreciated.

 

Thanks

 

H Patel

CEO

Data Entry India


script to align selected objects to artboard

$
0
0

Hello, I was wondering if anyone had a simple solution to aligning selected items to the artboard. I was going to create an action but then realized it would be more convenient for me to include it in my script file....I have a script to align objects with each other but they dont align to the artboard. Any suggestions?

Is it possible to distinct New document and Saved file in Documents??

$
0
0

It seems to me that .saved property is not answer.

[JS] CS6+ executeMenuCommand

$
0
0

Hello together,

 

since CS6+ there is possible to

executeMenuCommand (menuCommandString: string)

Executes a menu command using the menu shortcut string.

 

Question 1:

Who knows a way to read all the available commands?

 

Question 2:

At the time I need 'Clear Guides'

 

app.executeMenuCommand ('Clear Guides')

app.executeMenuCommand ('Clear guides')

app.executeMenuCommand ('clear Guides')

app.executeMenuCommand ('ClearGuides')

app.executeMenuCommand ('clear guides')

 

and other variants doesn't work.

 

Who know the right syntax? (Or is this menu command not available????)

 

 

Any help is appreciated. (Additional: I know the way to use app.doScript (myAction) - but this is not part of my questions)

trouble positioning ellipse in new layer

$
0
0

I created  new layer in my document, and then a new ellipse inside that layer.

I am trying to position the new ellipse at the top of the layer (vertically) and in the center of layer along the x axis (horizontally).

Nothing I have tried seems to move the object left of the layers starting x position (I can move it right just fine!?!).

I am confused because my top and height properties of the layer are negative numbers - but when I look at the ruler, all are above zero?

What am I doing wrong in terms of positioning the ellipse in the layer?

 

Here is a sample of my script:

var childLayer = currentLayer.layers[j];
var xmin = childLayer.pageItems[0].geometricBounds[0].toFixed(2); // top
var ymin = childLayer.pageItems[0].geometricBounds[1].toFixed(2); // left
var xmax = childLayer.pageItems[0].geometricBounds[2].toFixed(2); // bottom
var ymax = childLayer.pageItems[0].geometricBounds[3].toFixed(2); // right

var newBoneLayer = boneLayer.layers.add();
newBoneLayer.name = childLayer.name.replace(OBJECT_MARKER, "");
var halfOfWidth = parseFloat(childLayer.pageItems[0].width/2).toFixed(2);
var boneGuideXPosition = parseFloat(xmin + halfOfWidth).toFixed(2);
var boneGuide = newBoneLayer.pathItems.ellipse(ymin,boneGuideXPosition, 10.0, 10.0, true, false);

boneGuide.stroked = true; 
boneGuide.filled = true; 
boneGuide.opacity = 40.0; // set to 40% opacity
var newRGBColor = new RGBColor();
newRGBColor.red = 204;
newRGBColor.green = 255;
newRGBColor.blue = 255;
boneGuide.fillColor = newRGBColor;

Convert .eps file to .jpg or .pdf

$
0
0
Hello,
I'm using Adobe to deal with .eps files.
My problem is to display graphic arts in "read only mode". That means when I'm done developing graphics in my .eps file, I want to display this graphics to other user without giving him option to edit it or delete it.
I'm trying to accomplish this true Visual Studio 2005, C# .net
Does somebody have any suggestions?

Tiny issue with a layer

$
0
0

Hi,

 

I'm currently trying to do the same copy to clipboard trick Muppet Mark-QAl63s showed me in this thread: http://forums.adobe.com/thread/840440?tstart=0

 

Unfortunately with my current document I get an error when trying to execute this:

var lineRef = app.activeDocument.pathItems.add();

 

and there error is: "Target layer cannot be modified"

....which is a bit cryptic to me. Why can't the layer be modified ?

I've printed to the console app.activeDocument.activeLayer.locked and it prints false.

 

What does that error mean and how can I get past it ?

 

Thanks in advance,

George

Script for making an object the artboard size.

$
0
0

I am looking for some help on trying to make an object the exact size of the artboard.  This is something I do on a daily basis for several different reasons and it would be very helpful if this can happen automatically for whatever size the artboard may be.  As I understand it the only way is with a script but I have no experience with making illustrator scripts, im definately no programmer.  I have set up quickkeys in the past to copy from the artboard inputs when you are on the artboard tool but these round to the nearest .01 and this is not accurate enough for what I am working with.  Also if I do this with multiple pages open illustrator is very slow to respond to the artboard tool.  If anyone has any idea where to start or has seen other such scripts I would greatly appreciate it.  Thank you.

 

Below is a script that I saw on here that I believe may contain what I need but now knowing programming I have no idea where to start on editing.  All I need is the part where an object is placed on the artboard that is the exact same size as the artboard.  If anyone can advise on editing I would greatly apprecaite it.

 

#target illustrator

function main() {
     if (app.documents.length == 0) {
          alert('Open a document before running this script');
          return; // Stop script here no doc open…
     }else{
          var docRef = app.activeDocument;
          with (docRef) {
               if (selection.length == 0) {
                    alert('No items are selected…');
                    return; // Stop script here with no selection…
               }
               if (selection.length > 1) {
                    alert('Too many items are selected…');
                    return; // Stop script here with selection Array…
               }else{                   
                    var selVB = selection[0].visibleBounds;
                    var rectTop = selVB[1] + 36;
                    var rectLeft = selVB[0] - 36;
                    var rectWidth = (selVB[2] - selVB[0]) + 72;
                    var rectHeight = (selVB[1] - selVB[3]) + 72;              
                    selection[0].parent.name = 'CC';
                    selection[0].filled = false;
                    selection[0].stroked = true;
                    var ccColor = cmykColor(0, 100, 0, 0);              
                    var ccCol = spots.add()
                    ccCol.name = 'CC';
                    ccCol.color = ccColor;
                    ccCol.tint = 100;
                    ccCol.colorType = ColorModel.SPOT;
                    var cc = new SpotColor();
                    cc.spot = ccCol;                   
                    selection[0].strokeColor = cc;
                    selection[0].strokeWidth = 1;                   
                    var tcLayer = layers.add();
                    tcLayer.name = 'TC';
                    var padBox = pathItems.rectangle(rectTop, rectLeft, rectWidth, rectHeight, false);
                    padBox.stroked = false;
                    padBox.filled = true;
                    var tcColor = cmykColor(0, 100, 90, 0);         
                    var tcCol = spots.add()
                    tcCol.name = 'TC';
                    tcCol.color = tcColor;
                    tcCol.tint = 100;
                    tcCol.colorType = ColorModel.SPOT;
                    var tc = new SpotColor();
                    tc.spot = tcCol;
                    padBox.fillColor = tc;    
                    padBox.move(docRef, ElementPlacement.PLACEATEND);
                    artboards[0].artboardRect = (padBox.visibleBounds);
                    redraw();
                    rectWidth = (rectWidth-72)/72;
                    rectWidth = roundToDP(rectWidth,1);
                    rectHeight = (rectHeight-72)/72;
                    rectHeight = roundToDP(rectHeight,1);
                    var textString = rectWidth + ' x ' + rectHeight;
                    prompt('Copy Me', textString);
               }         
          }
     }
}

main();

function roundToDP(nbr, dP) {
     dpNbr = Math.round(nbr*Math.pow(10,dP))/Math.pow(10,dP);
     return dpNbr;
}

function cmykColor(c, m, y, k) {
     var newCMYK = new CMYKColor();
     newCMYK.cyan = c;
     newCMYK.magenta = m;
     newCMYK.yellow = y;
     newCMYK.black = k;
     return newCMYK;
}


Batch combine files into one illustrator document - how to open target document?

$
0
0

I am making a script which will:

 

1) Open a folder of Illustrator files

2) Open each file in the folder (these files are called the source files)

3) Select all the contents of the source file

4) Copy the contents of the source file

5) Paste these contents into a target file as a new layer

6) Ensure the new layer has the same name as the old source file

 

 

However, I don't know how to tell Illustrator where my target file is. How can I do this?

 

Also, when I paste, how can I turn off paste rembers layers. (So the layers get pasted into the new layer that has the same name as the old document).

 

Here is my code:

 

 

// JavaScript Document

 

 

//Set up vairaibles

var destDoc, sourceDoc, sourceFolder;

 

 

// Select the source folder.

sourceFolder = Folder.selectDialog('Select the folder with Illustrator files that you want to mere into one', '~');

 

 

// If a valid folder is selected

if (sourceFolder != null) {

          files = new Array();

 

 

          // Get all files matching the pattern

          files = sourceFolder.getFiles();

 

 

          if (files.length > 0) {

                    // Get the destination to save the files

                    destDoc = document.selectDialog('Select the final saved document', '~');

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

                              sourceDoc = app.open(files[i]); // returns the document object

 

                              var myLayers = sourceDoc.layers; // All layers in Active Document

 

 

                              //Go through all layers of source document and copy artwork

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

                                        myLayers[i].hasSelectedArtwork = true;

                              };

 

 

                              with(sourceDoc) {

                                        var count = pageItems.length;

                                        for (var i = 0; i < count; i++) {

                                                  pageItems[i].selected = true;

                                        }

                                        redraw();

                                        copy();

                                        for (var i = 0; i < count; i++) {

                                                  pageItems[i].selected = false;

                                        }

 

 

                              }

 

 

                              //Create a new title variable that has the title of the source document

                              var title = sourceDoc.name;

                              var title = title.substring(0, title.length - 4); //(remove extension from name)

                              //Close the Source Document

                              sourceDoc.close(SaveOptions.DONOTSAVECHANGES);

 

 

 

 

                              //Open the Destination Document and create a new layer in it that is named after the title variation

                              var newLayer = destDoc.layers.add();

                              newLayer.name = title;

 

 

                              //Paste into this new layer

                              destDoc = app.paste();

 

 

                    }

          }

          else {

                    alert('No matching files found');

          }

 

}

 

Thanks in advance for any help   

 

Edit: Also, when pasting, how can I paste in place instead of just pasting.

batch exporting mulitple ai files to jpeg (+ exporting artbords)

$
0
0

First, let me start by saying how awesome you guys are for being able to write scripts.

 

I have about 250 ai files, each with two artboards.

 

Is there anyway I can export the ai files to jpegs but also exporting each artboard into its own jpeg.

 

I hope that makes sense.

Here's an example.

 

When I open one of the illustrator files, there are two art boards. I  can go File>Export> and choose 'jpeg' then check 'use artboards' then hit export, I can achieve what I want. I would like to do this to all 250 ai files with a script.

 

appreciate any help on this!

Extracting unique identifier for illustrator layers

$
0
0

Hi All,

 

Multiple layers in an illustrator file can have the same name. So the layer name cannot be a unique identifier for layers. Is there a way to extract a unique identifier for layers through scripting? I saw that if the 'Identify Objects by' property (inside Preferences -> Units) is set to XML ID, all layer names, even identical ones are replaced by some unique ids. Can we extract these ids via scripting without manually changing the 'Identify Objects by' property. Basically, extraction of any unique identifier for illustrator layers would serve the purpose. I am really stuck with this and need help urgently. Any help would be highly appreciated.

 

Thanks in advance.

Copy selection to a new document

$
0
0

Here is a break down of what I am wanting to accomplish....any guidance would be appreciated!

 

1. User will select items (text frames, compound path items, path items)

2. User will run a script that will do the following....

     1. Open a new document (8.5" x 11") with RGB color

     2. Anything with a fill color should get gray color 100% fill applied

     3. Anything with a stroke color should get gray color 100% stroke applied

     4. Then save a .ai file and a .pdf file in the following format.....

 

#target illustrator


var doc = app.activeDocument;
var fileName = doc.name;
var jobName = (fileName).substr(0, 11);
aiFile = "D:\\Jobs\\"+jobName+"\\AI\\Cover Page.ai" 
pdfFile = "D:\\Jobs\\"+jobName+"\\PDF\\Cover Page.pdf" 


var newaiFile = new File(aiFile); 
doc.saveAs (newaiFile);  
var pdfOpts = new PDFSaveOptions();     
pdfOpts.pDFXStandard=PDFXStandard.PDFXNONE; 
pdfOpts.compatibility = PDFCompatibility.ACROBAT5;     
pdfOpts.preserveEditability = false; 
var newpdfFile = new File(pdfFile);     
doc.saveAs(newpdfFile, pdfOpts);

Script to make multiple layers in one task

$
0
0
From time to time I find the need to make many empty layers named A-Z. I use this when preparing a font drawn in Illustrator for moving to FontLab.

I have not found any ready made script to do this and would like a little help to make one. Or, if somebody would like to make this script it would be even more helpful.

The situation is this:
A full set of glyphs is ready in Illustrator and all are on Layer 1.
Artboard is set according to: http://font.is/?p=48
Glyphs are aligned to left on top of each other.
Need to make empty layers, A-Z and even more. Tedious by hand.
Then each glyph is moved from the sublayers to their own new layers. I could continue doing this part by hand.

I could of course make these layers in one file and copy them each time to each project but a script would be soooo much cooler.

Any help with this? Hints?

Thanks in advance.
Viewing all 12845 articles
Browse latest View live


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