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

Error 21 (Changing color on text)

$
0
0

http://forums.adobe.com/message/5580527#5580527

 

Carlos wrote a script in response to the above thread. It changes CMYK black, and grayscale black to a swatch called "spot black". It's awesome, but it's only aimed at paths. I've made some adjustments to prevent it from effecting white and unpainted objects. I'm going to need it to work on text and gradients. Right now I am working on text.

 

I've tried to use the same logic that works on the paths on text, but I'm missing something. Help help.

Screen Shot 2013-08-13 at 9.39.43 AM.png

 

This is the latest working version, it does not effect text or gradients.

// script.name = cmykBlackNgrayscaleToSpotBlack.jsx;
// script.description = changes art color from standard CMYK Black and Grayscale tones to an EXISTING Spot swatch named "spot black";
// script.requirements = an opened document;
// script.parent = CarlosCanto // 08/08/13;
// script.elegant = false;

// reference http://forums.adobe.com/thread/1267562?tstart=0

// Note: color values get rounded to the nearest integer, to avoid values like black = 99.99999999999999
//            Hidden and/or Locked Objects will be ignored, as well as objects in Hidden and/or Locked Layers

#target Illustrator

var idoc = app.activeDocument;
var pi = idoc.pathItems;
var sw = idoc.swatches["spot black"];
var fcounter = 0;
var scounter = 0;

for (j=0; j<pi.length; j++) {    var ipath = pi[j];    if (ipath.layer.visible==true && ipath.layer.locked==false && ipath.hidden==false && ipath.locked==false) {        var fillColor = ipath.fillColor;        if (fillColor.typename == "CMYKColor") {            if (isColorBlack (fillColor)) {                var fillk = Math.round(fillColor.black);                cmykBlackToSpot (ipath, true, false, fillk);                fcounter++;            }        }        else if (fillColor.typename == "GrayColor") {            if (grayNotWhiteOrClear (fillColor)) {                var fillk = Math.round(fillColor.gray);                cmykBlackToSpot (ipath, true, false, fillk);                fcounter++;            }        }        var strokeColor = ipath.strokeColor;        if (strokeColor.typename == "CMYKColor") {            if (isColorBlack (strokeColor)) {                var strokek = Math.round(strokeColor.black);                cmykBlackToSpot (ipath, false, true, strokek);                scounter++;            }        }        else if (strokeColor.typename == "GrayColor") {            if (grayNotWhiteOrClear (strokeColor)) {                var strokek = Math.round(strokeColor.gray);                cmykBlackToSpot (ipath, false, true, strokek);                scounter++;            }        }    }
}
alert(fcounter + ' Fill(s) & ' + scounter + ' stroke(s) processed');

function cmykBlackToSpot (path, fill, stroke, k) {
    if (fill) {        path.fillColor = sw.color;        path.fillColor.tint = k;    }    if (stroke) {        path.strokeColor = sw.color;        path.strokeColor.tint = k;    }
}

function isColorBlack (cmykColor) {
    var c = Math.round(cmykColor.cyan);    var m = Math.round(cmykColor.magenta);    var y = Math.round(cmykColor.yellow);    var k = Math.round(cmykColor.black);    if (c==0 && m==0 && y==0 && k != 0)        return true    else        return false
}
function grayNotWhiteOrClear (GrayColor) {    var pct = Math.round(GrayColor.gray);    if (pct != 0)        return true    else        return false
}

 

This is the version I'm working on now where I'm trying to include the text.

 

// script.name = cmykBlackNgrayscaleToSpotBlack.jsx;
// script.description = changes art color from standard CMYK Black and Grayscale tones to an EXISTING Spot swatch named "spot black";
// script.requirements = an opened document;
// script.parent = CarlosCanto // 08/08/13;
// script.elegant = false;

// reference http://forums.adobe.com/thread/1267562?tstart=0

// Note: color values get rounded to the nearest integer, to avoid values like black = 99.99999999999999
//            Hidden and/or Locked Objects will be ignored, as well as objects in Hidden and/or Locked Layers

#target Illustrator

var idoc = app.activeDocument;
var pi = idoc.pathItems;
var sw = idoc.swatches["spot black"];
var ch = idoc.textFrames[0].characters[0];
var fcounter = 0;
var scounter = 0;

for (j=0; j<pi.length; j++) {    var ipath = pi[j];    if (ipath.layer.visible==true && ipath.layer.locked==false && ipath.hidden==false && ipath.locked==false) {        var fillColor = ipath.fillColor;        if (fillColor.typename == "CMYKColor") {            if (isColorBlack (fillColor)) {                var fillk = Math.round(fillColor.black);                cmykBlackToSpot (ipath, true, false, fillk);                fcounter++;            }        }        else if (fillColor.typename == "GrayColor") {            if (grayNotWhiteOrClear (fillColor)) {                var fillk = Math.round(fillColor.gray);                cmykBlackToSpot (ipath, true, false, fillk);                fcounter++;            }        }        var strokeColor = ipath.strokeColor;        if (strokeColor.typename == "CMYKColor") {            if (isColorBlack (strokeColor)) {                var strokek = Math.round(strokeColor.black);                cmykBlackToSpot (ipath, false, true, strokek);                scounter++;            }        }        else if (strokeColor.typename == "GrayColor") {            if (grayNotWhiteOrClear (strokeColor)) {                var strokek = Math.round(strokeColor.gray);                cmykBlackToSpot (ipath, false, true, strokek);                scounter++;            }        }    }
}

for (t=0; t<ch.length; t++) {    var txt = ch[t];    if (txt.layer.visible==true && txt.layer.locked==false && txt.hidden==false && txt.locked==false) {        var fillColor = txt.fillColor;        if (fillColor.typename == "CMYKColor") {            if (isColorBlack (fillColor)) {                var fillk = Math.round(fillColor.black);                cmykBlackToSpot (txt, true, false, fillk);                fcounter++;            }        }        else if (fillColor.typename == "GrayColor") {            if (grayNotWhiteOrClear (fillColor)) {                var fillk = Math.round(fillColor.gray);                cmykBlackToSpot (txt, true, false, fillk);                fcounter++;            }        }        var strokeColor = txt.strokeColor;        if (strokeColor.typename == "CMYKColor") {            if (isColorBlack (strokeColor)) {                var strokek = Math.round(strokeColor.black);                cmykBlackToSpot (txt, false, true, strokek);                scounter++;            }        }        else if (strokeColor.typename == "GrayColor") {            if (grayNotWhiteOrClear (strokeColor)) {                var strokek = Math.round(strokeColor.gray);                cmykBlackToSpot (txt, false, true, strokek);                scounter++;            }        }    }
}
alert(fcounter + ' Fill(s) & ' + scounter + ' stroke(s) processed');

function cmykBlackToSpot (path, fill, stroke, k) {
    if (fill) {        path.fillColor = sw.color;        path.fillColor.tint = k;    }    if (stroke) {        path.strokeColor = sw.color;        path.strokeColor.tint = k;    }
}

function isColorBlack (cmykColor) {
    var c = Math.round(cmykColor.cyan);    var m = Math.round(cmykColor.magenta);    var y = Math.round(cmykColor.yellow);    var k = Math.round(cmykColor.black);    if (c==0 && m==0 && y==0 && k != 0)        return true    else        return false
}
function grayNotWhiteOrClear (GrayColor) {    var pct = Math.round(GrayColor.gray);    if (pct != 0)        return true    else        return false
}

 

Here is a test file

https://docs.google.com/file/d/0BzEoJSYDhH_WdENjc092SF9GN0U/edit?usp=sharing

Thanks for playing.


ungroup all groups on an active layer(JavaScript).

$
0
0

Does anyone know how one would go about ungrouping all groups on an active layer with JavaScript?

Unable to select same Graphic style on pasted eps

$
0
0

I open an eps.

Copy the whole graphic.

Open correct template and paste copied graphic.

The template has Graphic styles with same fill and stroke (no other attributes exist) as in pasted graphic.

However, I cannot select elements in pasted graphic based on Graphic Style even though pasted graphic contains elements with same stroke and fill.

I cannot select on same stroke and fill either.

 

I checked Document Colour Mode and made sure it was RGB Color.

However, when I select the element and double click Color Picker the initial window is showing New Color 1100 so I suspect even though the same style illustrator is assigning the element color and stroke as new.

 

This selection process is a step in an action for applying styles and has worked - then it doesn't.

 

Probably something simple is changing parameters but appreciate suggestions as to where the issue might lie.

 

This is old CS2 on Mac PPC G5 but still pays for itself doing simple processing of output files.

 

Any advice appreciated as many hours trying to figure this out.

 

Thank you

 

Michael

Access and return properties of placedItem.file

$
0
0

I'm trying to assign properties of placedItem.file. However, whenever I try to access placedItem.file it prints/returns "undefined is not an object".

 

I've used the alert command to print the object e.g. alert(placedItem.file) and it prints the file location of the image. However, when I try to assign that value to a variable ( var exampleName = placedItem.file ) it also returns the same error.

 

I've also tried accessing sub properties of file, like file.fullName and file.displayName. It returns the same error. If anyone has insight that would be awesome. I really just need to return the path of an image to a variable.

Illustrator Macros/Scripting

$
0
0
Hey guys is it possible to create macros in illustrator, or how would this be achieved via the scripting.

Basically i have a c# application that contains alot of pictureboxes all with images in them. i want to be able to right click an image and select vectorise. Which will send the image to illustrator live trace the image, resize it, then copy the resulting image back into my c# app.

How would this be best done

thanks
r

Illustrator script to open file in Photoshop

$
0
0

The Bridge SDK has a script to open a selected file in Photoshop.

Can this  be done from Illustrator instead?

 

It seems that the cross-dom function open() should work in either an illustrator or bridge script, yet the following does NOT work in Illustrator.

Fresh from the Bridge 5.1 SDK, it doesn't work in Bridge either, but that's for a different forum.

 

var t = app.activeDocument.fullName;

Photoshop.open(new File(t));

 

It provides me with Error 2: Photoshop is undefined.

 

So, any ideas on how to make this work?

This is all leading up to the real problem, which is to create a 150dpi jpg file, which Illustrator won't do.

 

Thanks All.

--Alex

Move layers to new artboard

$
0
0

Hi everybody,

 

I'm trying to create a script via javascript for Illustrator.

 

My problem is :

I have a AI file with multiple layers, i want to create one artboard per layer, in order to export a multipage PDF ( each page contain 1 layer ).

 

The layers represents the differents type of print ( vernish, color, hot gold, pressure ... ) and/or color type ( Pantone, CMYK, cut, kisscut ... ).

My client want a PDF for see each type of print or color type per page.

 

I'm trying 2 ways :

 

1st solution : Create new artboards, and duplicate ( or move ) layers content on the new artboad, but the function move/duplicate don't work to move content on another artboard.

 

2nd solution : Create new document with the same number of layers as artboard and duplicate layer to the new artboard on the new document.

 

Can you help me to realize this script ?

 

Excuse me if my english is not good.

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


Can I get some value from user? (illustrator cs3 script)

$
0
0

I am Designer. But I have to write program.

 

I will making plugin about draw rectangle.

 

 

 

1. User run illustrator cs3.

 

2. User click File-Scripts-myDraw

 

3. Show dialog box. Dialog box have two inputField. User input values.(ex>53.32,   41.2)

 

4. click 'summit' button.

 

5. illustrator cs3 draw 53.32 * 41.2 size rectangle!!

 

 

 

I don't know How I made dialogbox...

 

Is it possible get value from user?

 

 

what is 'cin' code as illustrator javascript?  (cin : C++ style input code.)

 

 

please help me.

Action to remove all unused swatches nearly works...

$
0
0

I've been using the default Action to remove fluff (unused swatches, symbols, brushes, etc.) but it has a funny quirk. I have a spot black color (named black) that always escapes the purge, even if it not used in the document. It is not set as the default stroke/fill, and there are no styles that use this swatch. Even if I run the Action twice the swatch remains. Even if I rename the swatch to something other than black it remains. Even if I rename the swatch and give it a different CMYK mix it remains. As a kludge, I've been using a combo of the default action and John Wundes' Delete Fluff script to get everything, but it is not an ideal solution. Wundes' script, which is unable to delete used brushes, roots out the offending swatch. It is unable to delete unused brushes, so following up with the default action clears those out. Also, Wundes' script is very slow and will often beach-ball the application, requiring a force-quit occasionally.

 

Two questions:

============

Can anyone think of other places that might harbor this rogue spot color and make the default action not find/delete it?

Is there a simple script that could check specifically for the use of this color in the document and delete it?


Cheers and thanks!!


-G-



Relink multiple images and export in jpg

$
0
0

Hi, this is my first post, been searching for nearly 2 hours for my solution, didn't end up with any answers

 

I have a template with the size of 500x500, there's my company logo at the right bottom and there's a brand's logo at the top left, i created a layer to put the products in the middle of the templates.

 

So now I have nearly 400 products to be relink and export into jpg, anyone can help me with this? I found out I have to use javascript for this and i have no clue of how to do this.

 

relink.png

 

I would like to have 2 folders, first folder is my product, second folder would be the export photos be at(with the same title would it be possible?).

so the script should be able to read from the first folder and relink the product automatically in the layer and export into jpg automatically and being saveinto the second folder. (all the product images have the same size so no worries about it.)

 

Million thanks!

How to check if a path fits inside of another path?

$
0
0

I've just been told that I need a script that will check and see if a path fits entirely within another path? In my case, I need to see if a GroupItem fits within a circle of a specific size. I don't see any methods available for PageItem that will do it for me, so does anyone know of a workaround? (Preferably without having to check every single PathPoint of every single item in the group.) I am using Illustrator CS6 and do my scripting with Javascript.

Extract text from illustrator for translation then replace with translated text

$
0
0

I am trying to find a way to expedite translations of our drawings.  Each drawing has a series of callouts showing what that piece of the drawing is via text.  I would need to do 100's of drawings for each book.

 

Questions:

 

1. Can I write something to batch a folder and extract the name of the file, and the text from each textbox so that when I get the translation back, I can automate the reinsertion of the translated text to its correct field (i.e. TextField1 = "Translate this" then repopulate that same exact field with "Translation")?  In order to do this I would think each text field would have to be tagged with some unique identifier so that it would know which translation goes where in the drawing.  Keep in mind, I'm ok with manually tagging each textbox if necessary.

 

2. Assuming the above is possible, what would be the best program to write the extracted text to so that reading and writing the translated text back into the drawing is as easy as possible (i.e. Word, Excel, PDF)?

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.

Make a clipping Path while retaining it's appearance - script

$
0
0

This has been a long standing wish of mine, and I've devised this script that "kind of" works.

 

This script takes your selection, copies appearance attributes, and pastes them to the top object after clipping.

 

It's currently limited in a few ways:

• It does not accept compound paths as clipping object (and I don't know how to test for it, nor how to iterate down said compound clipping object to set each path object to clipping separately)

• It only works with a single stroke or fill

• It does not understand "no fill" it will fill your object with white instead *FIXED*

• I'm hoping to use the "graphicStyle" property to copy the appearance, since that sounds way cleaner. But I don't understand how to.

 

 

Even with these limitations, I bound this to CMD+7 using fastscripts - I'm *already* used to it working this way!

Carlos Santos, thank you for writing the base of what became this script

 

I'd be much obliged if anyone can help me out with any of those limitations / wishes.

 

#target Illustrator

//  script.name = Clip Retaining Color.jsx;
//  script.required = at least two paths selected, top most path is the clipping mask;
//  script.parent = Herman van Boeijen, www.nimbling.com // 30/11/13;
//  *** LIMITED TO A SINGLE STROKE AND/OR FILL OF THE CLIPPING OBJECT***
//  Here's hoping to use the "graphicStyles" property to copy over the appearance.


if ( app.documents.length > 0 ) {    idoc = app.activeDocument;
}else{    Window.alert("You must open at least one document.");
}


var idoc = app.activeDocument; // get active document;
var sel = idoc.selection; // get selection
var selectedobjects = sel.length;


function ClipRetainingColour(idoc){
    var lay = activeDocument.activeLayer    if(lay.locked || !lay.visible){        alert("Please select objects on an unlocked and visible layer,\nthen run this script again.");        return;    }    var igroup = lay.groupItems.add(); // add a group that will be the clipping mask group    var imask = sel[0]; // the mask is the object on top    var clipcolors = [];    //copy appearance    if(imask.filled)     {clipcolors.fillColor = imask.fillColor;}    if(imask.stroked)    {        clipcolors.stroked = imask.stroked;        clipcolors.strokeWidth = imask.strokeWidth;        clipcolors.strokeColor = imask.strokeColor;    }     for (var i = selectedobjects-1 ; i > 0 ; i--){        var ipath = sel[i];        ipath.move(igroup, ElementPlacement.PLACEATBEGINNING);    }    imask.move (igroup, ElementPlacement.PLACEATBEGINNING);       //enable clipping    igroup.clipped = true;    imask.clipping = true;    //paste appearance    if(clipcolors.fillColor)    {imask.fillColor = clipcolors.fillColor;}    if(clipcolors.stroked)      {        imask.stroked = clipcolors.stroked;        imask.strokeWidth = clipcolors.strokeWidth;        imask.strokeColor = clipcolors.strokeColor;    }
}


if (selectedobjects){
    ClipRetainingColour(idoc);
}

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

Pg Number, File path and date automatically printed?

$
0
0

Is there a way to automatically print the page number, complete file path and date at bottom of each  page (set to landscape)?

 

Thanks!

ChangeSizesOfTextSelection.js

$
0
0

Illustrator version 10 installed with a sample script named ChangeSizesOfTextSelection.js. The script gradually changes the size of text.

 

The way it works is, you type some text in Illustrator, select it as an object, and run the script. The script incrementally decreases the size of the text until it gets to the center character, and then it incrementally increases the size of the text. This works in Illustrator 10. However, in Illustrator CS4 it doesn't do a thing. Below is a copy of the script.

 

I'd love it if someone could help out with a fix for the script so that it is usable in CS4.

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

 

// change size of paragraph text

 

//$.bp();

 

ChangeSize();

 

function ChangeSize()
{
    selectedItems = selection;
    // check to make sure something is selected.
    if (selectedItems.length == 0)
    {
        alert("Nothing is selected");
        return;
    }

 

    endIndex = selectedItems.length;

 

    for (index = 0; index < endIndex; index++)
    {
        pageObject = selectedItems[index];
        pageItemType = pageObject.typename;

 

        if (pageItemType == "TextArtItem")
        {
            // get the paragraphs from the selection.
            theTextRange = pageObject.textRange();
            paraTextRange = theTextRange.paragraphs;
            numParagraphs = paraTextRange.length;

 

            for (i = 0 ; i < numParagraphs ; i++)
            {
                aParagraph = paraTextRange[i];

 

                charTextRange = aParagraph.characters;
                charCount = charTextRange.length;

 

                if (charCount > 1)
                {
                    halfWay = Math.round(charCount/2);
                    fontSizeChanger = 36/halfWay;
                    currentFontSize = 48;
                    for (j = 0 ; j < halfWay-1; j++)
                    {
                        theChar = charTextRange[j];
                        theChar.size = currentFontSize;   
                        currentFontSize = currentFontSize - fontSizeChanger;
                    }
                   
                    for (j = halfWay; j < charCount ; j++)
                    {
                        theChar = charTextRange[j];
                        theChar.size = currentFontSize;
                        currentFontSize = currentFontSize + fontSizeChanger;
                    }
                }
            }
        }
    }
}

Placing registration marks on the corners of document

$
0
0

I have to process a lot of files to be router trimmed which requires them to have very specific registration marks.  There are 2 different marks we have to use.  The first mark is at the top left corner of the image contains 2 .25" dots separated vertically by a 1" gap.  The other mark is one .25" mark that is in the top right, bottom right, and bottom left corners.  I have both of these registration marks saved as symbols (or just AI files).  I want to be able to have the script automatically place the appropriate marks in the corners.  How can this be done?

 

Thanks!

Chris

Exporting an .ai file to a bitmap file

$
0
0

In Illustrator Scripting (VBscripting), how can you export an ai file to a bitmap file?

 

In Illustrator you can open an ai file and by selecting the Export option you have a choice of formats and one of them is BMP.  How can this be done in scripting?  I did look at the AIExportType, but BMP is not in the list.

 

aiJPEG = 1

aiPhotoshop = 2

aiSVG = 3

aiPNG8 = 4

aiPNG24 = 5

aiGIF = 6

aiFlash = 7

aiAutoCAD = 8

 

I will also need to do this same method by Exporting to an eps file.

 

The task is the following:

 

When a client uploads an image file, we need to automatically export the file to bmp and to esp, thus having 3 files (original upload, bmp, and esp).  The file types that we are exporting, so far, will be ai, esp, and pdf (more to follow I am sure).

 

We also need to get information about each file.

Is it vector or a bitmap?

Color:  RGB, CMYK, or Pantone?

Is there text or curves or both?

What is the DPI resolution?

What is the image size?

 

Any help would be beneficial.

 

Thanks,

 

Tom

 

 

 

 

 

 

 

 

 

 

 

 

Viewing all 12845 articles
Browse latest View live


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