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

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.


Can anyone help with changing colors without making a selection

$
0
0

I've been trying to work the the script below. All the front most paths are black I want to change them all to yellow without having to select them first.

 

Any help would be really appreciated. "I am a novice javascripter"

 

var myStyles = app.activeDocument.pathItems;

lastStyle=myStyles[myStyles.length-1]

lastStyle.remove();

frontStyle=myStyles[0]

frontStyle.filled=true;

 

 

 

// Sets the default fill color in the current document to yellow.

if ( app.documents.length > 0 ) {

//added

 

frontPath = frontStyle;

 

// Define the new color

var newRGBColor = new RGBColor();

newRGBColor.red = 255;

newRGBColor.green = 255;

newRGBColor.blue = 0;

// Use the color object in the path item

frontPath.filled = true;

frontPath.fillColor = newRGBColor;

}

Need script to batch convert vector .eps to .png images with scale

$
0
0

Hi,

 

I'm looking for a script/program that if you run it, all the .eps files in a folder will batch convert to a png-24 with 250% scale.

 

Erdem

Perform grep search

$
0
0

Hi folks,

 

I was wondering whether it was possible to find and replace using grep. I have the find and replace thing sorted, but I need it to be flexible enough to select any number and alter the value by a set amount. I have done this in InDesign but have become stuck with Illustrator.

 

I have tried to use an adapted version of the search script from this thread: (CarlosCanto)

 

var multiplier = parseFloat(2.5);

 

var search_string = /[-]*[0-9][0-9,.]*\\b/gi;

var replace_string = search_string * multiplier;

 

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;

        }

    }

}

 

This simply returns 'undefined'

 

Do I need to invoke a grep function to parse the pattern through?

 

Any help would be wonderful.

 

Thanks

JavaScript to prompt user to save as PDF

$
0
0

I am making changes with code to the file. I want the user to be prompted to save as a .ai file first. I have that down. Now I am wanting to have the user immediately be prompted to save as a pdf with only the optimize for fast web view option selected. I believe it is an adobe preset of Smallest File Size.

The reason for wanting the prompt is because I want to save the files in 2 different locations.

Here is my code so far.....

var doc = app.activeDocument;
// Save as .ai file 
var fileName = doc.fullName; 
var thisFile = new File(fileName);
var saveFile = thisFile.saveDlg();
doc.saveAs (saveFile);


// Save as .pdf file
var pdfSaveOptions = new PDFSaveOptions(); 
pdfSaveOptions.pDFXStandard=PDFXStandard.PDFXNONE; 
pdfSaveOptions.compatibility = PDFCompatibility.ACROBAT5; 
pdfSaveOptions.preserveEditability = false;  
var pdfFile = new File(fileName); 
doc.saveAs(pdfFile, pdfSaveOptions);

AI CS4 Windows 7 64bit

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.

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

Set Stroke Alignment from JavaScript

$
0
0

Hi,

 

I'm trying to set the stroke style for a path item I've drawn through JavaScript, however I can't find a way to set the stroke alignment for my path item.

I've checked the Illustrator JavaScript reference but I can't seem to find that option in there.

I would expect something like:

 

pathItem.strokeAlignment = StrokeAlignment.OUTSIDE; // This doesn't work, what is the correct way to set the stroke alignment from JavaScript?

 

If I change the option in the Actions Panel it comes up as 'Set Stroke/Alignment: Outside', so there must be an equivalent way of setting it from JavaScript.

Is there a way of converting Actions to JavaScript so you can see which properties and attributes are being set on the object?

 

Does anyone know the correct way to set the strok alignment from JavaScript?

 

Thanks!


How to rename a layer like filename (with an action)

$
0
0

Could anyone help me to rename a layer of illustrator like document file name? (with an action)

Thank you

Mauro

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

Startup Script for Illustrator only

$
0
0

Hi,

 

I've made a nice palette script for Illustrator CS6 on OSX 10.6.8.

I put it into HD/Library/Application\ Support/Adobe/Startup\ Scripts\ CS6/Illustrator

 

I works fine in Illustrator.

 

BUT: If I start Indesign CS6, the palette show up twice and it is not possible to close both pallettes.

 

Any hints?

 

Next question: The palette is used to have an easy access to script. If I start the scripts with the palette, the error messages of the scripts are not displayed. If I start individal script directly in Illustrator errors are displayed. What can I do?

 

Thanks for your help.

 

 

 #target illustrator;

#targetengine main;

//var pfad = "/Applications/Adobe\ Illustrator\ CS6/Presets.localized/de_DE/Skripten/"
var pfad = "/Volumes/Platte/Hilfsmittel/Skripte/"

var win = new Window('palette', 'Daniels Zauberkiste');
var tpanel = win.add ("tabbedpanel");
tpanel.alignChildren = ["fill", "fill"];
tpanel.preferredSize = [100,20];
win.margins = 0;
win.spacing = 0;
var subtab1panel = tpanel.add ("tab", undefined, "allgemein");
subtab1panel.orientation="row";
subtab1panel.alignChildren = ["fill", "fill"];


var t1group = subtab1panel.add("group");
t1group.orientation = "column";
t1group.alignChildren = ["fill", "fill"];


var btnSelect1 = t1group.add('button', undefined, 'Passer');
var scriptToLoad1 = new File(pfad+"_Passer-Montage.jsx");
var btnSelect2 = t1group.add('button', undefined, 'Prüfpasser');
var scriptToLoad2 = new File(pfad+"_Prüfpasser-Montage.jsx");
var btnSelect3 = t1group.add('button', undefined, 'Kontur+10');
var scriptToLoad3 = new File(pfad+"_Kontur+Dok+10.jsx");
var btnSelect4 = t1group.add('button', undefined, 'Kontur+20');
var scriptToLoad4 = new File(pfad+"_Kontur+Dok+20.jsx");
var btnSelect5 = t1group.add('button', undefined, 'Standardbogen Stanze');
var scriptToLoad5 = new File(pfad+"_Bogengröße.jsx");


btnSelect1.onClick = function(){
      var des = scriptToLoad1;   des.open("r");         var bt = new BridgeTalk;   bt.target = "illustrator";         var script = des.read();   des.close();              bt.body = script;   bt.send();  
}// end function


btnSelect2.onClick = function(){
      var des = scriptToLoad2;   des.open("r");         var bt = new BridgeTalk;   bt.target = "illustrator";         var script = des.read();   des.close();              bt.body = script;   bt.send(); 
}// end function


btnSelect3.onClick = function(){
      var des = scriptToLoad3;   des.open("r");         var bt = new BridgeTalk;   bt.target = "illustrator";         var script = des.read();   des.close();              bt.body = script;   bt.send();
}// end function


btnSelect4.onClick = function(){
      var des = scriptToLoad4;   des.open("r");         var bt = new BridgeTalk;   bt.target = "illustrator";         var script = des.read();   des.close();              bt.body = script;   bt.send();
}// end function


btnSelect5.onClick = function(){
      var des = scriptToLoad5;   des.open("r");         var bt = new BridgeTalk;   bt.target = "illustrator";         var script = des.read();   des.close();              bt.body = script;   bt.send();
}// end function










win.center();
win.show();

Can javascript execute pathfinder commands?

$
0
0

Can javascript execute menu commands such as pathfinder options?

Is it possible in Extendscript/Javascript to 'Outline Stroke' a path

$
0
0

I'm trying to achieve the same command as enacted by Object > Path > Outline Stroke.

 

I can't find any reference to a method for this in the Javascript reference PDF, and you can't trigger menu commands in Javascript.

 

Applescript allows you to access the menu commands, so I wrote this:

 

tell application "Adobe Illustrator"

    set thisDoc to current document

    set locked of layer ("walls") of thisDoc to false

   

end tell

 

tell application "System Events"

    click menu item "All" of menu "Select" of menu bar item "Select" of menu bar 1 of process "Adobe Illustrator"

       

    click menu item "Outline Stroke" of menu "Path" of menu item "Path" of menu "Object" of menu bar item "Object" of menu bar 1 of process "Adobe Illustrator"

   

end tell

 

But it has a very annoying problem: if you run the script form within Illustrator the 'Outline Stroke' command fails. But, if you run the script in the Applescript editor with the illustrator document open it works. Which is just plain weird. If anybody understands why this is the case I'd love to hear the reason (and fix).

 

If anybody has any ideas for successfully outlining strokes in either Javascript or Applescript please respond.

 

Thanks,

 

Barry

Dialog in Illustrator CS4 js

$
0
0

Hi,

 

I have dialog script that I am using in InDesign to choose a pdf file to place into the document and I need exactly the same script in Illustrator, but  I have a hard  time to  translate it into Illustrator scripting format. I don't have much information about building dialogs in Illustrator. Could someone help me.

 

 

var myDialog = app.dialogs.add({name:"Holiday Templates",
canCancel:true});
with(myDialog){
//Add a dialog column.
with(dialogColumns.add()){

//Add a dialog column.
with(dialogColumns.add()){
   
    // Radius radio buttons //
    with(borderPanels.add()){
        staticTexts.add({staticLabel:"Choose Holiday Template:"});
        var myRadioButtonGroup = radiobuttonGroups.add();
        with(myRadioButtonGroup){
        var myEighthRadius = radiobuttonControls.add
        ({staticLabel:"4x6_flower", checkedState:true});
        var myQuaterRadius = radiobuttonControls.add
        ({staticLabel:"4x6_heart"});
        }
    }
}



    var myResult = myDialog.show();
    if(myResult == true){

var myFolderPath = myPath + "/~prepress/HolidayTemplatesFilePrep/";

        // Radio buttons readings //
        if(myRadioButtonGroup.selectedButton == 0){
        myTemplateA = File (myFolderPath + "/~4x6_flower.pdf");
        myTemplate2A = File (myFolderPath + "~4x6_flower_back.pdf");
        }
        else if(myRadioButtonGroup.selectedButton == 1){
        myTemplateA = File (myFolderPath + "/~4x6_heart.pdf");
        myTemplate2A = File (myFolderPath + "/~4x6_heart_back.pdf");
        }


        myDialog.destroy();
        myHolidayTemplates();
    }
    else{
        myDialog.destroy();
    }

}
}

 

Thank you very much for your help.

 

Yulia

Simple InDesign script -> Illustrator help

$
0
0

I have this script by Peter Kahrel that reverese the order of letters in InDesign.

 

I need an Illustrator version of it. Can anybody help?

 

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

//ReverseText.jsx

//An InDesign Javascript that reverses the order of any selected text.

//If no text is selected with the Type tool, nothing happens.

//Written by Peter Kahrel for InDesignSecrets.com

//****************

 

#target indesign

if ( "TextWordLineParagraph".search ( app.selection[0].constructor.name ) < 0 )

    exit();

s = app.selection[0].contents;

s = s.split("").reverse().join("");

app.selection[0].contents = s;

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

 

Mainly using this for Arabic text in CS 3 and 4 for clients that don't have new versions - and will never buy it apparently.

 

Works great in InDesign. I've been putting the text in ID and then copying it into Illustrator. But it would be nice to skip that step if possible.

 

Thanks in advance.


Help with a script to work on mac

$
0
0

I am not a mac user...

I am trying to help EWO54 out with putting CMYK / RGB values into a .csv file.

I have written a basic script. but he is having trouble getting it to work correctly on his mac.

i would love for someone to step in and help out where my knowledge fails.

see:

Export of color values to Excel

 

Thanks in advance guys/gals...

All Group to Ungroup Script

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.

Changing decimal values to fractions

$
0
0

Does anyone know of a good way to convert decimal values to fractions for use in inch measurements? I have a script that works great but it returns values like 5.5638 and I'd rather it return the closest fraction answer like 5 9/16. 1/16ths would be great, but I'd settle for 1/8ths.

 

I started trying to come up with a large if with lots of > and < conditions, but I figured if anyone has already done this it might be better not to reinvent the wheel.

 

Thanks.

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);          }    }
Viewing all 12845 articles
Browse latest View live