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

How to export each raster image as pdf

$
0
0

Hi all,

Can anybody please help with creating a script that will export each raster image in the AI document/layer as a PDF with certain save options ?

 

Right now im doing it manualy, turning on/off each object/raster image individualy and saving the file each time changing the name  manualy according to raster image/object name.

I have to do this on lots of files each with hundreds of objects.

 

If anybody is interested, im willing to cover the expenses for creating this script, as i need it urgently. Please contact me by email at duda.jan@gmail.com

 

Any help is greatly appreciated.

pdf-script02.jpg


split txt-file into 3 xml files

$
0
0

I'm trying to create 3 xml files from 1 txt file in javascript.

 

What i have sofar:

 

A text file containing:

 

GP0006896###SunGold-3 small###00###Zespri Service Centre NV###KLT0000110###16950###tray Kiwi SunGold 3-pack Small###JWM###ZESPRI-3-D$$$

GP0012816###S500-R012336###00###Poppies Nederland BV###KLT0000081###17890###Plus slagroomsoes 250g###JWM###CULI-10-B$$$

GP0009000###test###01###Just a test###KLT0001010###20596###Dit is een test regel###Standaard###TEST-01-B$$$

 

The script:

 

// Set variable

var txtfolderpath = app.path+'/XML_converter/';

var txtfilename = 'txt_to_xml.txt';

var txtfilelocation = File(txtfolderpath+txtfilename);

var xmlfolderpath = app.path+'/XML_converter/xml/';

var retChar = eval('String.fromCharCode(13)');

var presscancelbutton = 0;

var appversion = app.version;

var appversionarray = appversion.split('.');

appversion = new Number(appversionarray[0]);

var xmlstring='';

//Scriptfolderpathcheck

#target Illustrator

var pathcheck = File($.fileName).parent.fsName;

infopanelmenu();

function infopanelmenu(){

    res =

    "dialog { \

        text:'TXT to XML:', \

        properties:{resizeable:false}, \

        margins: [0,0,0,0], \

            imagegroup: Group { orientation:'stack', preferredSize: [400, 221], alignChildren:'bottom', \

                jobgroup: Group { orientation:'column',  margins: [0,0,0,20], \

                    infopanelgroup: Panel { orientation:'column', preferredSize: [360, 20], alignChildren:'top', text: 'TXT to XML conversion', \

                        xmlgroup: Group { orientation: 'row', alignment: 'left', \

                            s: StaticText { text:'XML converted : ' }, \

                            s2: StaticText { text:'0' }, \

                        } \

                        statusgroup: Group { orientation: 'row', alignment: 'left', \

                            s: StaticText { text:'Status              : ' }, \

                            s2: StaticText { text:'Ready to start' }, \

                        } \

                    } \

                    infopanelbuttons: Group { orientation: 'row', alignment: 'center', \

                    cancelBtn: Button { text:'Cancel', properties:{name:'cancel'} }, \

                    applyBtn: Button { text:'Start', properties:{name:'apply'} }, \

                } \

            } \

        } \

    }";

    wininfo = new Window (res);

    wininfo.frameLocation = [100, 100];

    // Buttons

    wininfo.imagegroup.jobgroup.infopanelbuttons.cancelBtn.onClick = function () {

        presscancelbutton = presscancelbutton - 1;

        wininfo.close();

    };

    wininfo.imagegroup.jobgroup.infopanelbuttons.applyBtn.onClick = function () {

        buildxml();

    };

    wininfo.center();

    wininfo.show();

}

function buildxml(){

    txtfilelocation.open('read');

    txtfile = txtfilelocation.read();

    var xmlarray = txtfile.split('$$$');

    wininfo.imagegroup.jobgroup.infopanelgroup.statusgroup.s2.text = 'Running';

    wininfo.imagegroup.jobgroup.infopanelbuttons.applyBtn.text = 'Running';

    wininfo.imagegroup.jobgroup.infopanelbuttons.applyBtn.enabled = false;

    // For lus schrijven

    for (i=0; i<xmlarray.length-1; i++) {

        var subxmlarray = xmlarray[i].split('###');

        var counter = i+1;

        var xmlstring = '';

        xmlstring = xmlstring + '<?xml version="1.0" encoding="UTF-8"?>'+retChar;

        xmlstring = xmlstring + '<xml>'+retChar;

        xmlstring = xmlstring + '<gp_number>'+subxmlarray[0]+'</gp_number>'+retChar;

        xmlstring = xmlstring + '<artikelnummer>'+subxmlarray[1]+'</artikelnummer>'+retChar;

        xmlstring = xmlstring + '<versienummer>'+subxmlarray[2]+'</versienummer>'+retChar;

        xmlstring = xmlstring + '<klantnaam>'+subxmlarray[3]+'</klantnaam>'+retChar;

        xmlstring = xmlstring + '<klantnummer>'+subxmlarray[4]+'</klantnummer>'+retChar;

        xmlstring = xmlstring + '<ID>'+subxmlarray[5]+'</ID>'+retChar;

        xmlstring = xmlstring + '<artikelomschrijving>'+subxmlarray[6]+'</artikelomschrijving>'+retChar;

        xmlstring = xmlstring + '<workflow>'+subxmlarray[7]+'</workflow>'+retChar;

        xmlstring = xmlstring + '<stans>'+subxmlarray[8]+'</stans>'+retChar;

        xmlstring = xmlstring + '</xml>'

        wininfo.imagegroup.jobgroup.infopanelgroup.xmlgroup.s2.text = counter;

        alert(xmlstring); // see if the stingbuild works <-- works here 3 times

        // Save function

        var filename = subxmlarray[0]+'.xml';

        var xmlsavelocation = File(xmlfolderpath+filename);

        xmlsavelocation.open('w');

        xmlsavelocation.writeln(xmlstring);// save the string <-- works here 3 times but generates two empty documents!

        xmlsavelocation.close();

    }

    txtfilelocation.close();

    wininfo.imagegroup.jobgroup.infopanelgroup.statusgroup.s2.text = 'Ready';

    wininfo.imagegroup.jobgroup.infopanelbuttons.applyBtn.text = 'Start';

    wininfo.imagegroup.jobgroup.infopanelbuttons.applyBtn.enabled = true;

}

 

The output:

 

output.png

 

You'll see that i get 3 files but 2 are 0 bytes.

 

The question:

 

Why can't i save the other two strings in a xml file?

 

Thanks Daniel

Making rectangle as the same as bounding box's size?

$
0
0

Can anyone help me on this? It'll be really neat for everything.

Dynamic Spell Checking

$
0
0

Hi All,

 

i am using Adobe Illustrator CC

 

is there a way to make it have dynamic spell checing underlining with a red squiggly line in Illustrator?

 

like programs such as MS word?

 

Regards,

Vinoth

Merging diagonal text together

$
0
0

Hi I'm trying to merge these groups of text together but i'm having trouble keeping the spaces after i merge it with my current code.

 

BEFORE

letters.PNG

AFTER

letters2.PNG

 

here is my current code

 

 


var textLayer = idoc.layers[0]
textLayer.name = "Text";


for (var i = 0; i < textLayer.groupItems.length; i++){    var tempText = ""       var anchor1 = textLayer.groupItems[i].textFrames[0].anchor    var anchor2 = textLayer.groupItems[i].textFrames[1].anchor       var TextOnAngle = IsTextOnAngle(anchor1[0],anchor1[1],anchor2[0],anchor2[1])       var TextAngleDeg = TextAngle(anchor1[0],anchor1[1],anchor2[0],anchor2[1])    for (var j = 0; j < textLayer.groupItems[i].textFrames.length; j++){        if (j == 1){            var newText = textLayer.groupItems[i].textFrames[j].duplicate(textLayer, ElementPlacement.INSIDE)                   }        if (tempText == "") {                tempText = textLayer.groupItems[i].textFrames[j].contents;          } else {                tempText = tempText + textLayer.groupItems[i].textFrames[j].contents;                               if(TextOnAngle){                                       if(j+1 < textLayer.groupItems[i].textFrames.length){                        var tempAnchor1 = textLayer.groupItems[i].textFrames[j].anchor                        var tempAnchor2 = textLayer.groupItems[i].textFrames[j+1].anchor                                                   var CurrentAngle = TextAngle(tempAnchor1[0],tempAnchor1[1],tempAnchor2[0],tempAnchor2[1])                                                   if(!(CurrentAngle <= TextAngleDeg+5 && CurrentAngle >= TextAngleDeg-5)){                                                       //alert(CurrentAngle)                                tempText = tempText + '\r'                                                   }                    }                }           }    };    //var newText = textLayer.textFrames.add()        newText.contents = tempText

};
 textLayer.groupItems.removeAll()


//gets the angle of the text
function TextAngle(x1,y1,x2,y2){
    var xDiff = x1 - x2    var yDiff = y1 - y2    return Math.atan2(yDiff, xDiff) * (180 / Math.PI)
}


// works out if text is on an angle or not
function IsTextOnAngle(x1,y1,x2,y2){

    if((x1 >= x2-0.1 && x1 <= x2+0.1) || (y1 >= y2-0.1 && y1 <= y2+0.1)){        return false    }else{        return true       }
}


//gets the angle of the text
function TextAngle(x1,y1,x2,y2){
    var xDiff = x1 - x2    var yDiff = y1 - y2    return Math.atan2(yDiff, xDiff) * (180 / Math.PI)
}


// works out if text is on an angle or not
function IsTextOnAngle(x1,y1,x2,y2){

    if((x1 >= x2-0.1 && x1 <= x2+0.1) || (y1 >= y2-0.1 && y1 <= y2+0.1)){        return false    }else{        return true       }
}

}



 

 

if anyone has any ideas on how i can go about working out where to insert the spaces that would be great.

 

thanks in advance

Sorting Layers

$
0
0

I have a map of the US that is broken down into counties.  Each state has its own layer and the counties are sublayers.  I am currently going through and naming all of the counties, but I need to be able to alphabetize them.  Is there a way to do this?

 

Thanks

Reworking Photoshop layer renaming script for Illustrator

$
0
0

The Photoshop scripting guru Paul R over at RetouchPro has created a really cool script to batch rename and number selected Photoshop layers. I haven't found anything similar on the Illustrator side.

 

He's given permission for me to post it here in my hopes that some Illustrator scripting genius could come up with a similar script for Illustrator. Would it be terribly difficult to convert this into something Illustrator could use?

 

http://www.mediafire.com/file/g7usr73u0236p0a/Rename_&_Renumber_Selected_Layers.jsx

 

http://www.mediafire.com/file/dbah74x13bsa74c/Rename_&_Renumber_Selected_Layers.jsx.zip

 

rename-layers.png

Moving objects jsx?

$
0
0

Hello everybody. Is there any way to move a object using its width? ex: "move to left a box with 10cm(width) using this value (10cm)". But I want to capture the width of any selected object.

Another thing: i want to select objects with same fillcolor and do something like: pathfinder>>add;

Thanks for any answer.

And sorry for my bad english.


Change font in Illustrator cs4 js

$
0
0

I need to assign specific font to my text and it doesn't work. What am I doing wrong:

 

 

var my_OUTSIDE_TextFrame = myInstrLayer.textFrames.add();
my_OUTSIDE_TextFrame.geometricBounds = ["1.6 in", "1 in", "1.85 in", "2.75 in"];
my_OUTSIDE_TextFrame.contents = "OUTSIDE";

var myParagraph = my_OUTSIDE_TextFrame.paragraphs.item(0);
try{
myParagraph.appliedFont = app.fonts.item("Myriad Pro");

}
catch(e){}
try{
myParagraph.fontStyle = "Bold";
}
catch(e){}

myParagraph.pointSize = 30;

 

And it's not placing it where I want it either.

 

Thank you very much for your help.

Yulia

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

New to Illustrator scripting, looking to make a Compound Path from Existing Paths/Compound Paths

$
0
0

I am wondering how to select existing paths (normal paths and compound paths) and make a new compound path.  Google does nothing for me on this....

 

I have begun to understand the basics of targeting objects and doing some basic changes such as width, height, textFont, positioning and such...but the Scripting Guide is hard for me to wrap my head around as far as compound paths.

 

I am also having issues understanding the differences between object references that either do or don't have an "s" at the end. I assume there is some uniformity to why many object references have both. Could someone explain the reasoning?

 

Example

 

pathItem

pathItems

 

 

Thanks in advance!!

James

Intermittent Javascript MRAP error

$
0
0

I have a for loop which moves all elements of an "Artwork" layer to a "working" layer so that I can edit the elemets without a chance of affecting the original layer:

 

for (var i=app.documents[0].layers['Artwork'].pageItems.length-1; i>=0; i--)

{

          try

          {

                    app.documents[0].layers['Artwork'].pageItems[r].duplicate(app.documents[0].layers['workin g'], ElementPlacement.PLACEATEND);

          }

          catch(e)

          {

                    alert(e);

          }

}

 

This seems to work fine for three or four documents, and then begins to return the following error:

 

Error: an Illustrator error occurred: 1346458189 ('MRAP')

 

Action on every document then returns this error, even ones on which it has previously worked. The only solution is to quit Illustrator and relaunch.

 

Am I missing something obvious?

 

Thanks in advance.

$300 For 2 Photoshop/Illustrator scripts- Applescript Preffered

$
0
0

I have been meaning to write these myself for months, but have been too busy, so we're trying to hire someone.

 

We would prefer these to be mostly Applescript, because I know Applescript and will be able to modify/maintain them, but we might consider all Javascript if there are no bites on Applescript.

 

There are probably bits in here that are not accessible to Applescript, that would need to be in Javascript. I think color overlays are not in the scripting dictionary and need to be figured out with scripting listener. That's fine, as necessary, to call Javascript from an Applescript. We just want it to be in Aplescript as much as possible.

 

If you're interested, please contact me:

 

Tom Ingling

800-620-1233 x251

t.ingling [att] rushordertees [dott] com

 

 

I assume that if you're interested, you'd want more information. We can provide example files in the "before" and finished states, talk or email about any questions you have, and I also have examples of some steps of the scripts functioning for reference.

Here is the outline of the two scripts:

 

 

Script 1: Assign Color Overlay

 

Overview:

This script would need to do the following in Adobe Photoshop. The script will be run from a command key.

 

Script Steps:

 

1. Ideally, read the current swatches on the swatch pallet in Photoshop. If this is a pain/impossible, then we’re open to getting this info from somewhere else. We can save out the info needed as a .csv or .txt and the script can just load it from there.

 

2. When the script is run, it presents a dialog with a list of the colors from the swatch pallet. The user chooses a color from the list.

 

3. It applies the color selected as a "Color Overlay" Layer Effect to the currently selected layer. If the layer already has a color overlay effect, it updates it to the selected color. The color overlay effect is applied with the “Screen” blending mode.

 

4. It changes the layer name to the name of the color that was selected

 

 

Script 2: Save Files and Convert Photoshop File to Spot Color Raster EPS

 

Overview:

The script will save out the active Photoshop file in multiple copies in different ways, place data on the clipboard, and then use Illustrator to convert one of the Photoshop files to a different format.

 

The open file when the script is run will always be a Photoshop file with layers, with the topmost layers named by colors as specified by the above “Script 1.” The files can have an arbitrary number of layers, but will all be in this format:

 

first layer [Some Color Name]

arbitrary number of additional layers, each with color names

Shirt [ <- this is a solid color layer]

Art [<- this is a single group containing arbitrary layers]

 

 

Script Steps:

 

1. The active file is saved out exactly as it is. When the script’s run, it presents a save dialog. The operator chooses the save folder location and file name. I will refer to this as “The Save Folder” The script will then check to see if there’s an “Art” folder in The Save Folder. If there is, it saves the file there. If not, it creates the “Art” folder and saves it there. If the file already exists, it automatically overwrites and does not provide a dialog about it.

 

2. Another copy is saved using “Save For Web. The original file was at 300 dpi and this copy is saved out bicubic down sampled to 72 dpi with the same inch dimensions. The save settings are {JPEG High, Progressive – off, Optimized – on, Embed Color profile – off, Quality – 72, Blur – 0, Matte – none, Convert To sRGB – yes}   This one has the same file name as the first copy (except for the file extension) and is saved in The Save Folder.

 

3. A flat copy of the art at the same dimensions but downsampled to 18 dpi is placed on the clipboard.

 

4. An intermediate file for Illustrator conversion is saved. This should probably be saved in a new folder in The Save Folder called “Intermediate Files.” This folder needs to be checked for and created only if necessary. The file should have a naming scheme such as “Intermediate File” & [existing file name]. This file is identical to file 1, except:

- the shirt layer and art folder are removed. This should probably be scripted as deleting the layer named “shirt” and everything below it in the file.

- all the color overlays are removed (or turned off)

 

5. Close the file.

 

6. Open the intermediate file in Illustrator with the “Convert Layers to Objects” option.

 

7. Select All

 

8. Edit -> Edit Colors -> Convert to Greyscale

 

9. Cycle through each layer one at a time and change the fill color to the swatch from an open Illustrator swatchbook called “Current Inks” with the same name as the layer name.

 

To clarify this previous step, our artists will be working off the same .ASE color swatchbook in both Photoshop and Illustrator. In Photoshop, the colors from this .ASE will be used as color overlays on layers. The file needs to be imported to Illustrator and have the same colors applied as fill colors of the raster objects that were the Photoshop layers. The color information is being conveyed from Photoshop to Illustrator through the layer names in Photoshop.

 

10. Save this file to The Save Folder as a .AI with the same name and “CONV”

 

11. Delete the intermediate file.

PathItems index method

$
0
0

Hello all, could anyone give me some examples of how to use the index method pathItems

 

thank you very much

Shear / Skew using shear angle and axis angle

$
0
0

Hi,

 

I want to skew/shear the selected object using shear angle and axis angle.

 

I am using below code for shear the object,

 

var skewMatrix = app.getIdentityMatrix();

skewMatrix..mValueB = .5

 

But i dont know how to apply the axis angle with this matrix.

 

any hints?


Excel data to construct illustrator object

$
0
0

Problem:

How to read real number data from selected columns in an Excel spreadsheet into an illustrator javascript array variable, so that then I can use this information to construct an illustrator polygon. 

 

Further information:

I am new to javascript (and not much of a programmer in the best case, but do have some basic knowledge using ancient languages like FORTRAN 88). I am sure I am just missing an important step here despite all morning browsing with Google for answers (something to do with variable definition I assume?). I have some survey data defining the outline of features in map view listed in a string of point (x,y) values in adjacent columns in excel (these x,y point values calculated from GPS data using a commercial program to converted 3D position to a 2D x,y by geoid projection, and then in excel to re-scale point locations to illustrator’s artboard).  What I am trying to do is select columns of x,y value pairs in an excel spreadsheet, copy these values to the clipboard, and then develop an IA JavaScript to draw a polygon through the specified set of x,y points. It seems easy enough to script illustrator to draw the polygon once I get the values from the clipboard are in a javascript array (lots a good tips here http://scriptographer.org/tutorials/), but pulling in the clipboard data seems to be beyond me. I have tried populating a defined array with various combinations of array declarations and app.paste(); or windows.clipboardData.getData('text/plain'); with no satisfaction. I then had the idea to try to pull in the clipboard to one long continuous string, place that in a text box (see see its structure), andthen read and split up the text in a loop to populate the JavaScript array…but that deposited a complex illustrator table object into my text box, and several attempts to force the clipboard to paste text did not work (again probably having problems understanding variable type declaration).

 

Thanks very much for any suggests….and to be clear, I would be happy to find any method of scripting the pull of the selected on an excel spreadsheet for use in an Illustrator script…so if I am making this all harder than it needs, be I would be grateful to know that also!

How do I make a custom shape using Javascript?

$
0
0

I would like to create a trapezoid shape and be able to color it in, just like I'm able to do with the PathItems (e.g. rectangle, ellipse). I would like to be able to do this in Javascript.

 

I was thinking it might have to do with PathPoints, but Adobe's Scripting Reference Guide does not make it clear.

 

If anyone could give me some quick sample code on how to do this, I'd be much appreciative. Or just a description would be great.

 

THANK YOU VERY MUCH

"Type Options" in "Document Setup" scriptable?

$
0
0

I would like to create a script (have not done one before) that changes the values of the superscript and subscript size/position in "Document Setup". After looking around, I did not see anything even related to this and only a comment on one site that it probably could not be done. So it this a lost cause? I have many files I would like to convert the values for.

 

Thanks.

How to save illustrator file without save as dialog ?

$
0
0

I' trying to save a file using 

 

app.activeDocument.saveAs(savepath);

 

and i am doing it in a loop on multiple files, but every time it will just show save as window and i have to do it manually.
Any ideas how to ignore that save as window ?

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

Viewing all 12845 articles
Browse latest View live


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