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

Batching In Illustrator??

$
0
0

In PhotoShop CS3, you can select File/Automate/Batch, and run an Action on an entire folder.  I don't see that option in Illustrator CS3?  Is there a way to run an action on an entire folder?

 

I'm attempting to save many EPS images as PNG images, and would really like to retain "vector attributes" - is any of this possible???

 

Thanks for any help.


Writing linked files name into AI file

$
0
0

Hello. I'm looking for a little help customizing the script below.

 

I would like the script to:

  1. Not include the file extension of the linked file in the file name
  2. Position the placed text relative to the top left hand corner of the linked file (not relative to the AI artboard)
  3. My linked file names have spaces in them. I would like the placed text to replace the "%20" with an actual space

 

//var Sel_itemPlaced = app.activeDocument.placedItems[0]; // if nothing is selected - use the first linked file item  
var sel_itemPlaced = app.activeDocument.selection[0]; // be sure that a linked item (and not an embedded) is selected  
//alert (sel_itemPlaced.file.name);  
var aTF = app.activeDocument.textFrames.add();  
aTF.position = [50,-50];  
aTF.contents = sel_itemPlaced.file.name; 

 

Many thanks so far to pixxxel schubser who has helped me get this far. This request spawned from Linked files name.

Error: an Illustrator error occurred: 271 ('')

$
0
0

Curious if anyone has run into this error? I get this error when running my script through ExtendScript Toolkit:

Error: an Illustrator error occurred: 271 ('')

 

This line is the code that causes the crash:

app.open( File( "D:\\Perforce\\srays_temp_temp\\NIComponents\\VisualDesign\\ProductionAssets\\DiagramPale tteAssets_XML\\SystemDesigner\\trunk\\1.3\\source\\SystemDesignerPalettes\\PalettePartsVie w_2_16x16.ai") );

 

The Adobe explanation is unclear what is causing it?

" The Add-on <addon-name> failed to install: There was a file operation error when installing this Add-on.

Failed to parse the file.

Solution: The extension (add-on) is corrupted. Download it again. To install another way, click Install Issues link in My Exchange or contact the Adobe Exchange Online Forum for assistance."

 

Thanks!

Scott

How to get bounds of largest possible document area?

$
0
0

Hello!

 

I'm trying to improve GuideGuide's handling of Illustrator guides. So far I haven't found a built-in way to add guides, so I draw a path and then set it's guides value to true. While this works, it has the drawback that I have to figure out the boundary locations of the guides in addition to where I want to place them.

 

For my example, I'm using a horizontal guide.

 

Looking at how Illustrator handles things, it appears to add guides at the max left and max right bounds of the document. Mind you, it's possible to place objects even farther beyond those bounds, but they're the bounds that Illustrator visually shows. This is the behavior I'm trying to emulate.

 

So far I haven't found a scripted way to extract those boundaries from Illustrator, but my testing has thus far shown that the document max height and width is 16383pts. One would think that it would be as simple as placing a guide edge at 0 and 16383, however the document origin appears to be in the center. One would then think that (16383/2) * -1 would be the document edge, but this also does not turn out to be true. So far, in my testing the document origin is fluid, sometimes in the center, sometimes offset. I tried incorporating the document pageOrigin, but that has also not proven to be helpful. I'm even taking into account the artboard/document coordinate system differences and have found no obvious solution yet.

 

Am I missing some obvious details that can be used to pull these values from Illustrator? This seems like something that would be relatively easy to do.

 

GPU Preview)  2016-09-13 09-04-36.png

Setting the bleed in AI via Javascript

$
0
0

Hi All,

 

I'm writing a function to change the artboard size and add bleed depending on certain conditions.

I can't actually believe this is causing me trouble but here it is, I'm trying to set the bleed dimensions in AI document with Javascript. All I've found so far is setting up PDF export options or print options, but not the actual artboard Document Setup. I just want to be able to set bleed to a newly created document like in this window:

So similar to Indesign:

 

with(myDocument.documentPreferences){  documentBleedUniformSize = true;  documentBleedTopOffset = 7;  }

 

(CC2017)

Screenshot 2017-04-06 15.45.28.png

how to access https site from javascript socket object

$
0
0

HI ,

 

I'm new to SSL's and scripting.

 

I have written code to access http site and it is working.Below is the code.The script is failing when i try to access https application.

 

Can some one please help me .

 

below is the code.

var request = [];

    request.push('POST', ' ', path, ' ', "HTTP/1.1\n");       

    request.push('Authorization:', 'Basic d2NhZG1pbjp3Y2FkbWlu==', '\n');

    request.push('Host: ', host, "\r\n");

    request.push('User-Agent: ', USER_AGENT, "");

    //request.push('Connection: ', 'close', "\n");

    request.push('Pragma: ', "no-cache", "\r\n");

    request.push('Accept: ', "*/*", "\r\n");

    request.push('Accept-Charset: ', "UTF-8", "\r\n");

    request.push('Accept-Language: ', "en-US", "\r\n");

    request.push('Content-Language: ', "en-US", "\r\n");

    request.push('content-location: ', file.name, "\r\n");

    //request.push('Content-Length: ', fileContents.length, "\r\n");

    request.push('Content-Length: ', content.length, "\r\n");

    request.push('Content-Type: ', 'multipart/form-data;boundary=', boundary, "\r\n");

    

    request.push('\n');

    request.push(content);       

      alert('request--->'+request); 

    //  5. Upload

    var socket = new Socket;   

    socket.open(host+':80', 'BINARY');

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

        socket.write(request[i]);

    }

How to test if two PathPoints are the same

$
0
0

I am trying to write a function that takes a PathPoint and returns its index relative to it's parent PathItem. Something like this:

 

function getPathPointIndex(pathPoint) {     var pathPoints = pathPoint.parent.pathPoints,          i,          length = pathPoints.length;     for (i = 0; i < length; i++) {          if (pathPoint === pathPoints[i]) {               return i;          }     }     return false;
}

 

However I have found when working with PathPoint objects even if they represent the same point they rarely identify as the same object. This can be demonstrated with the following example. Create a new Illustrator document and draw a path with at least two points then run the following:

 

var pointA = app.activeDocument.pathItems[0].pathPoints[1],     pointB,     i,     length = pointA.parent.pathPoints.length;

for (i = 0; i < length; i++) {     var pointB = pointA.parent.pathPoints[i];     if (pointA === pointB) {          $.writeln('index ' + i + ': Same');     } else {          $.writeln('index ' + i + ': Different');     }
}

 

On my system the pointA and pointB are never the same. It doesn't make much that a point doesn't exist in it's parent element.

 

You will notice that I used the second PathPoint (index 1) to demonstrate this issue. This is because the script works as expected if the first PathPoint (index 0) is used.

 

It would be great if somebody could please:

1. Explain this phenomenon

2. Provide a solution to testing if two PathPoints are the same

3. Get the index of a PathPoint relative to its parent PathItem (this should be easy if point to can be achieved)

 

Thanks

Retrieve whats in the clipboard possible?

$
0
0

Is it possible to retrieve whats in the clipboard through a script?

If so how?


Resolution check in illustrator

$
0
0

How to check the raster image resolution in illustrator through script?

Set unit preferences (Javascript)

$
0
0

I can't find a way to set the unit preferences for Illustrator CS6/CC using JavaScript.

 

I found that this works (setting units for stroke):

var units = 2; // 0-inches, 1-milllimeters, 2-points

app.preferences.setIntegerPreference("strokeUnits", units)

 

But I want to set the ruler units ("General" in the interface), and this does not work:

app.preferences.setIntegerPreference("rulerUnits", units)

 

Any help?

Peter

Unembed All Images?

$
0
0

Hi everyone,

 

I was just wondering if there could be a "unembed all images" script out there. I have a pdf previously created in Word that I've imported into AI CC 2015 and need to create links out of all the embedded images in the doc.

 

Any help or reply is greatly appreciated,

 

Thanks!

 

 

Andy

Javascript to make selection of top level group?

$
0
0

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

 

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

 

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

 

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

 

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

 

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

 

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

 

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


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

 

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

 

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

How to put swatches in a swatchGroup using javascript?

$
0
0

I can't figure this out for the life of me. 

 

I have these functions that work great.  It puts the SpotColor swatches into the swatch panel.

 

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

function getColorNumbers() {
    var colorNums = []    for (i = 0; i <= 10; i += 1) {    colorNums.push(i / 100);    }        for (i=0;i<colorNums.length;i++) {      createNewSpotColor(colorNums[i]);      }      return colorNums;
}

function createNewSpotColor(color) {
     //Define the new color value    var newColor = new CMYKColor();    newColor.cyan = 0;    newColor.magenta = 0;    newColor.yellow = 0;    newColor.black = color;        //Create the new spot    var newSpot = app.activeDocument.spots.add();    //Define the new SpotColor    newSpot.name = color.toString();    //newSpot.tint = 0;    newSpot.typename = SpotColor;    newSpot.color = newColor;   // create a spotcolor object     newSpot.colorType = ColorModel.SPOT;    var newSpotColor = new SpotColor();    newSpotColor.spot = newSpot;    //newSpotColor.tint = 0;
 }

getColorNumbers();

 

Now I would like to put these swatches into a swatchGroup.  I've tried several things.  One of my tries worked but put every individual swatch into it's own swatchGroup.  All the other times I can get the swatches in the panel and a new swatchGroup added, but can't get the swatches in the swatchGroup.

 

var doc = app.activeDocument;  
var colorgroup = doc.swatchGroups.add();    colorgroup.name = 'Cad colors';          var selSwatch = doc.swatches.getSelected();      var swatch = doc.swatches;        for (a=0; a<swatch.length; a++) {        if (swatch[a].color == SpotColor) {          swatch[a].selected = true;          if(swatch[a].selected == selSwatch) {            colorgroup.addSpot(selSwatch);                }     } 
 }

 

What am I missing?

Miximize window by script

creating outlines from text using javascript in Illustrator CS5

$
0
0

Hi everyone,

 

Is there a way to select all of the text on all artboards and CREATE OUTLINES using Javascript? I've googled and googled, but I can't seem to find any help. The text that Adobe provides for scripting has this option for saving to FXGs which is preserveTextPolicy or something similar, but I need the same type of solution for saving as an AI file or as a command before the save. I'm currently working in windows, but am writing this script for use on a MAC. If there isn't an internal way of doing this through Javascript, does anyone know of another?  I would imagine it would be possible through Applescript since it can access the application's GUI, but I'm not sure. A javascript solution would be preferable, but any solution would work at this point.

 

thanks,

Matt


Script to crop artwork to artboard

$
0
0

I have some SVG graphics where the features/polygons 'hang out' over the edge of my artboard by a tiny amount. Is there a way (via script) of cropping all my shapes such that nothing hangs out over the edge of the artboard?

 

I have some script that creates a rectangle which is the exact size of my artboard. Using the menus (not script) I can then use that rectangle as a clipping mask over everything else which makes everything appear to be cropped, although what I'd actually like to do is properly, permanently modify all my polygons, rather than just having a visible clipping mask (and I need to do it all in script too). I'm then exporting the SVG files (hundreds of them) to DXF and what I don't want is coordinates of polygons that fall outside of the defined artboard boundary.

 

These are tesselating map tiles that are eventually making their way to GIS software to form a much larger map, so I don't want these little slivers of overhanging features as they end up overlapping each other at teh tile boundaries in teh final map.

 

Thanks!

Hide nested layers with same name?

$
0
0

I'd like to create a Javascript to hide all nested layers sharing the same name. For example, I'd like to hide all nested layers with the name "Mask" in this sample layer list:

This is a repetitive task for our production artists and a script would make their lives easier. Any help is appreciated.

Save multiple pdf problem...

$
0
0

Hello Everyone, i need some help here. I'm a JS noob and have no idea what i am doing. I managed to put a script together that is made of several scripts.
Everything works fine until the very end.
I need to export my ai. file to 3 pdf files named:
filename.pdf
filename_K.pdf (converted to outlines)

filename_P.pdf (converted to curves, without layers)

 

The  thing is that i can't find a way to export my third pdf without layers. Sometimes it does everything right, but sometimes it doesent.

 

 

 

Can someone help me with this?

 

Here my currents script:

 

#target illustrator 

function Filename(){ 

  var doc = app.activeDocument; 

  var parentPath = Folder(File(doc.fullName).parent); 

  var opts = new PDFSaveOptions();

  opts.pDFPreset = "Polpharma (cartons)"; 

  doc.saveAs(File(parentPath + "/"), opts); 

}; 

Filename();

 

 

#target illustrator 

 

function outlineDocText(  ) { 

 

          if ( app.documents.length == 0 ) return; 

   

  var docRef = app.activeDocument; 

   

          recurseLayers( docRef.layers ); 

   

}; 

 

outlineDocText();  

 

function recurseLayers( objArray ) { 

   

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

   

                    // Record previous value with conditional change 

                    var l = objArray[i].locked; 

                    if ( l ) objArray[i].locked = false; 

   

                    // Record previous value with conditional change 

                    var v = objArray[i].visible; 

                    if ( !v ) objArray[i].visible = true; 

   

                    outlineText( objArray[i].textFrames ); 

   

                    // Recurse the contained layer collection 

                    if ( objArray[i].layers.length > 0 ) { 

                              recurseLayers( objArray[i].layers ) 

                    } 

   

                    // Recurse the contained group collection 

                    if ( objArray[i].groupItems.length > 0 ) { 

                              recurseGroups( objArray[i].groupItems ) 

                    }  

   

                    // Return to previous values 

                    objArray[i].locked = l; 

                    objArray[i].visible = v; 

          } 

}; 

 

function recurseGroups( objArray ) { 

   

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

   

                    // Record previous value with conditional change 

                    var l = objArray[i].locked; 

                    if ( l ) objArray[i].locked = false; 

   

                    // Record previous value with conditional change 

                    var h = objArray[i].hidden; 

                    if ( h ) objArray[i].hidden = false; 

   

                    outlineText( objArray[i].textFrames ); 

   

                    // Recurse the contained group collection 

                    if ( objArray[i].groupItems.length > 0 ) { 

                              recurseGroups( objArray[i].groupItems ) 

                    }  

   

                    // Return to previous values 

                    objArray[i].locked = l; 

                    objArray[i].hidden = h; 

          } 

}; 

 

 

function outlineText( objArray ) { 

   

          // Reverse this loop as it brakes the indexing 

          for ( var i = objArray.length-1; i >= 0; i-- ) { 

   

                    // Record previous value with conditional change 

                    var l = objArray[i].locked; 

                    if ( l ) objArray[i].locked = false; 

   

                    // Record previous value with conditional change 

                    var h = objArray[i].hidden; 

                    if ( h ) objArray[i].hidden = false; 

   

                    var g = objArray[i].createOutline(  ); 

   

                    // Return new group to previous Text Frame values 

                    g.locked = l; 

                    g.hidden = h; 

   

          } 

 

}; 

 

 

#target illustrator 

function Filename_K(){ 

  var doc = app.activeDocument; 

  var parentPath = Folder(File(doc.fullName).parent); 

  var opts = new PDFSaveOptions();

  opts.pDFPreset = "Polpharma (cartons)";

  PDFSaveOptions.acrobatLayers = false;    

  doc.saveAs(File(parentPath + "/" + doc.name.replace(/\.\w+$/, "_K.pdf")), opts); 

}; 

Filename_K(); 

 

 

#target illustrator 

function Filename_P(){ 

  var doc = app.activeDocument; 

  var parentPath = Folder(File(doc.fullName).parent); 

  var opts = new PDFSaveOptions();

  opts.pDFPreset = "Polpharma (cartons)";

  doc.saveAs(File(parentPath + "/" + doc.name.replace("_K.pdf", "_P.pdf")), opts); 

}; 

Filename_P(); 

 

 

 

 

 

 

 

 

Thank you for your time!

[Q] Can we Deselect Objects by executeMenuCommand()?

$
0
0

Short question:

 

Can we Deselect Objects by executeMenuCommand()?

Is there any way to Deselect Object(s) by ExtendScript without overwriting Undo History?

 

Note:

Illustrator UI operation (Control + Shift + A) does not overwrite Undo History.

But by script (app.selection = [];) does overwrite (and redo history is gone).

I could not find parameter for executeMenuCommand(), so it is not tried yet.

  ref) Illustrator CC2017 Menu Commands Reference | CC Labo

This might be related to other polygon redo issue.

  app.redo() and app.redraw() delete manually operated Polygon object's undo history

 

 

Long and detail question:

 

Purpose

Deselect object after Undo without overwriting Undo history

 

Manual operation steps: (it works)

a-1) Place circles x 10 times

a-2) Undo (Control + Z) x 5 times

   Note: One circle is selected

a-3) Deselect object (Control + Shift + A)

   Note: Selected object is deselected

a-4) Redo (Control + Z) x 5 times

 

Expected result: Back to after a-1)'s step

Actual result: Works fine

 

Script operation steps: (it does not work)

b-1) Place circles x 10 times by manually

b-2) Run following test code

 

 

Expected result: Back to after b-1)'s step

Actual result: Redo does not work

 

Note: if b-1) steps is done by script object is not selected, and work as expected.

 

I'm not sure what is good way to Deselect Objects, but I tried following 2 ways.

I think setter is triggering adding undo/redo entry.

Is there other way?

 

NG:

app.selection = [];

 

NG:

for(var i = 0; i < app.selection.length; i++){ // Same as app.selection = []

    app.selection[i].selected = false;

}

 

Test code

#target illustrator

 

 

// open document before run

 

 

 

/*

// Place 10 circle

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

    $.writeln("polygon: " + i);

    var a = 100 + i * 20;

    activeDocument.pathItems.ellipse(-a, a, 10, 10, false, true);  // Circle

    app.redraw();

    $.sleep(1000);

}

*/

 

 

 

 

 

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

    app.undo();

    $.writeln("undo:" + i);

    app.redraw();  // no change

    $.sleep(1000);

}

 

 

 

// Deselect all object

 

 

app.selection = [];  // NG: overwrite undo history: redo does not work

 

 

 

// NG: Following also not work

//for(var i = 0; i < app.selection.length; i++){ // Same as app.selection = []

//    $.writeln("unselect:" + i);

//    app.selection[i].selected = false;

//}

 

 

 

app.redraw();

 

 

 

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

    app.redo();

    $.writeln("redo:" + i);

    app.redraw();

    $.sleep(1000);

}

 

 

app.redraw();

Illustrator CC Script to Auto Size Artboard and Save File name

$
0
0

HI,

Not very familiar with scripting for Illustrator. Need to create a script, preferably for batches of files. Need to add small extension to artboard to files and auto add the file name and save. Is this possible? Any help would be greatly appreciated.

Viewing all 12845 articles
Browse latest View live


Latest Images

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