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

No Stroke No Fill not recognizing

$
0
0

Can someone tell me why my else if statement isn't working? I know I have 3 path items that have no fill and no stroke...

#target illustrator
var allDocs = app.documents;
var doc = app.activeDocument;
var allLayers = doc.layers;
var allLines = doc.pathItems;
var counter = 0;
for (var i = 0; i < allLines.length; i++) {    if (allLines[i].layer == "[Layer Tables]") {        if (allLines[i].stroked == true) {            counter++;            allLines[i].remove();        } else if (allLines[i].stroked == false && allLines[i].filled == false) {            counter++;            allLines[i].remove();        }    }
}
alert(counter + " items removed");

 

Adobe Illustrator CS4 Windows 64 Bit JavaScript


Alphabetize text frames, duplicate and make a list in order

$
0
0

I am trying to take the selected text, sort it alphabetically, then duplicate all the text so it comes out in a list form.

So if I had the following text selected....

selected text.JPG

And ran my script....which I have just a vague start on...

#target illustrator
var doc = app.activeDocument;
var selectedItems = doc.selection;
var alphaList = [];


for (i = 0; i < selectedItems.length; i++){  alphaList.push(selectedItems[i]);  }
alphaList.sort();

 

The results would be this....

Capture.JPG

Anyone have any guidance for me? Thanks in advance!

Export to AutoCAD error

$
0
0

Hi everybody,

maybe here is anyone that can help me with my problem, because I've no idea, where my mistake is.

 

I tried to use a script (JavaScript) to automatically export each layer of an Illustrator file. The desired file format is AutoCAD, which shall not be a problem, because manual exporting works fine.

 

So my approach was hiding all layers except one and then export the file with the document.exportFile()-method. This exportFile()-method works with all other formats like svg, png or jpg, but when I try to call the method with an ExportOptionsAutoCad-argument, i receive the following error message:

Error 1320: Invalid enumeration value

Line: 25

->

document.exportFile(file,ExportType.AutoCAD,options);

 

So here is the crucial code of my script, I hope anyone of you has an idea, why this script isn't working.

 

Thank you!

if(document && folder)
{          var options = new ExportOptionsAutoCAD();     options.colors = AutoCADColors.TrueColors;     options.rasterFormat = AutoCADRasterFormat.PNG;     options.unit = AutoCADUnit.Millimeters;     options.version = AutoCADCompatibility.AutoCADRelease18;          var n = document.layers.length;     for(var i=0; i<n; ++i)     {          hideAllLayers();          var layer = document.layers[i];          layer.visible = true;               var file = new File(folder.fsName+"/"+layer.name+".dwg");          document.exportFile(file,ExportType.AutoCAD, options);          }          showAllLayers();
}

Possible to change linked images without AI?

$
0
0

Hi All!

 

I am relatively new to AI javascript coding, but I can't seem to solve my most recent problem. My company has 2 offices, each with their own local network server, but both offices can connect to the other's server. So California can connect to New York and vice versa. We transfer a lot of AI files between the two servers so that different people in the different offices can work on them.

 

The problem comes to linked images. If someone in New York tries to open a file from the California office, Illustrator is basically crippled if the image is linked to the CA server. I created a script that would copy the files (using a save as) to NY and relink them on that side, but bc you are still opening a file and saving it across a slow network connection so it isn't really a super efficient solution. Large files can take up to 3 min to save across the connection.

 

We can't apply the simple solution of just keeping the linked images in the same folder with the AI file, since we all have access to both servers it never breaks the link, and AI just grinds to a halt.

 

I found this post (http://stackoverflow.com/questions/524020/how-do-you-find-the-paths-of-linked-images-in-ad obe-illustrator-9) about using perl to read the header of the AI file and report back link names, but I know nothing about perl to know if you could have it go in there and change the link path. I also tried opening it in a text editor, changing the file path, but when I tried to open it back up in AI it said it was corrupted, so that doesn't seem to work.

 

Any ideas for an efficient way to change the absolute path of a linked file in AI without having AI open and trying to actually place the files over a slow connection? We basically just need to replace OAKServ with NYCServ in the link name, everything about the file organization is the same.

 

Our back up plan is to embed images, but some intial tests show that it can make AI slow and save times become a nightmare. I would love to avoid embedding if possible! Open to any other suggestions about other people's experience with working with files across multiple networks.

 

Stats: Illustrator CS5, PC (gross, I know), Windows 7, 64-bit OS

 

Thanks all! Love this forum!

Merging Layers

$
0
0

Hello,

 

I'm wondering if anyone knows if it is possible to merge all layers in an Illustrator document via ExtendScript. I've looked through the documentation but I can't see any methods to do this like the Photoshop scripting engine seems to have.

 

What I have is an Illustrator template with 3 layers that I am applying a data set to but would like to merge all the layers once the data set has been applied. I have all that stuff working, just needing a point in the right direction to get the layers merged.

 

TIA!

Save file with script (skip warning 'modified outside Illustrator')

$
0
0

Hi All,

 

We all know that command:

 

app.activeDocument.save();

 

saves the document skipping all the dialogs and even alert that is popping out every time when you manually saving your file on a server:

Screen Shot 2015-04-04 at 11.03.58.png

 

My issue is that I am working on PDF files (with preserved Illustrator editing capabilities) almost all the time rather than .ai files, and everytime I use

 

app.activeDocument.save();

 

The .ai file is created.

 

My question is if it's possible to save PDF that you're working on same as you would manually 'Save' from the menu context, ommiting that annoying dialog about modified file?

 

Regards

Peter

Is there a way to clear or delete actions through scripting?

$
0
0

Hello Everyone!

 

Menu Commands Outline Stroke

 

I'm trying to make a script that will clear and then reload actions to try to get around that bug. Thanks to quertyfly and moluapple I now know how to make actions through script so all I need to know if there is a way to clear actions through script.

 

Thanks Everyone!

Illustrator 2015 changes?

$
0
0

I don't see any new docs available on adobe's scripting page for AI. Does anyone know if there were any changes to the scripting engine?


Java Script: How select all corner points?

$
0
0

Java Script: How select all corner points in opened document?

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

ScriptUI: How to update Listbox values? (CC2014)

$
0
0

Is there way to update listbox element that filled with JS array elements. If I push more elements to the array, how I can re-render it in ScriptUI? Is there way to do this.

 

I know there is way just to add elements to listbox like in Peter Kahrel's PDF. But this isn't so dynamic:

 

var w = new Window ("dialog");
var myList = w.add ("listbox", undefined, ["one", "two", "three"]);
var b = w.add ("button", undefined, "Add");
b.onClick = function () {myList.add ("item", "zero", 0)}
w.show ();

 

How about if I wan't to update listbox when I have changed my arrays, like below:

 

// Create example array
var testArr = ['item1', 'item2']
$.writeln(testArr.length);

startGUI();
function startGUI() {
       // Window    var win = new Window( "palette", script_name, undefined, { resizeable:true } );    win.orientation = "column";    win.alignChildren = ["fill", "fill"];       // Listbox    var myListbox = win.add ("listbox", undefined, testArr,         {         numberOfColumns: 1,         showHeaders: true,         columnTitles: ['Name']    });    // Add Item To Array    var addItem = win.add("button", undefined, "Add Item");    addItem.onClick = function() {          testArr.push ('item3');        $.writeln(testArr.length);    }     // Quit BTN    win.quitBtn = win.add("button", undefined, "Close");    win.quitBtn.onClick = function() {          win.close();      }    win.show();
}

 

Maybe there is some update funtion on ScriptUI. I tried to search solution without success. Any help?

Advanced "Save as PDF" script that saves 2 PDF presets with 2 different names.

$
0
0

Hi Everyone,

 

I am looking to improve a save as pdf workflow and was hoping to get some direction. Here is the background...

 

I routinely have to save numerous files as 2 separate PDFs with different settings (a high res printable version and a low res email version). Each file has to be renamed as follows...

 

Original filename = MikesPDF.ai

High Res PDF Filename = MikesPDF_HR.pdf

Low Res PDF Filename = MikesPDF_LR.pdf

 

I was able to alter the default "SaveAsPDF" script to save the files to my desired settings and to add the suffix to the name. So with these scripts here is how the workflow operates...

 

1. Open all files I wish to save as pdfs

2. Select script to save files as high res pdfs

3. Illustrator asks me to choose a destination.

4. Illustrator adds the appropriate suffix and saves each file as a pdf to my desired setting. ("Save As" not "Save a Copy").

5. Now all of the open windows are the new pdfs, not the original ai files.

6. Now I have to close each window. For some reason Illustrator asks me if I want to save each document when I tell it to close window, even though the file was just saved. I tell it to not save and everything seems to be fine.

7. Reopen all the files I just saved as high res pdfs.

8. Repeat the entire process except I run the script specifically designed for the low res pdfs.

 

What I would like to do is to combine these two processes so that there will be one script that saves both pdfs. From what I understand, the script can't support "Save A Copy" so the workflow would go as follows...

 

1. Open all files I wish to save as pdfs

2. Select single script to save files as both high res and low res pdfs

3. Illustrator asks me to choose a destination.

4. Illustrator saves each file as a High Res PDF and adds the the "_HR" suffix.

5. Illustrator then re-saves the open windows as a Low Res PDF and replaces the "_HR" suffix with "_LR".

 

Here is the code for the High Res script, The Low Res script is pretty much the same except for a different preset name and different suffix. Any pointer that anyone could give me would be most appreciated. I am pretty much a noob to this stuff so please keep that in mind.

 

Thanks!

Mike

 

---------------------------CODE----------------------------

 

/** Saves every document open in Illustrator

  as a PDF file in a user specified folder.

*/

 

 

// Main Code [Execution of script begins here]

 

 

try {

  // uncomment to suppress Illustrator warning dialogs

  // app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

 

 

  if (app.documents.length > 0 ) {

 

 

  // Get the folder to save the files into

  var destFolder = null;

  destFolder = Folder.selectDialog( 'Select folder for PDF files.', '~' );

 

 

  if (destFolder != null) {

  var options, i, sourceDoc, targetFile;

 

  // Get the PDF options to be used

  options = this.getOptions();

  // You can tune these by changing the code in the getOptions() function.

 

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

  sourceDoc = app.documents[i]; // returns the document object

 

  // Get the file to save the document as pdf into

  targetFile = this.getTargetFile(sourceDoc.name, '.pdf', destFolder);

 

  // Save as pdf

  sourceDoc.saveAs( targetFile, options );

  }

  alert( 'Documents saved as PDF' );

  }

  }

  else{

  throw new Error('There are no document open!');

  }

}

catch(e) {

  alert( e.message, "Script Alert", true);

}

 

 

/** Returns the options to be used for the generated files. --------------------CHANGE PDF PRESET BELOW, var NamePreset = ----------------

  @return PDFSaveOptions object

*/

function getOptions()

{var NamePreset = 'Proof High Res PDF';

  // Create the required options object

  var options = new PDFSaveOptions();

     options.pDFPreset="High Res PDF";

  // See PDFSaveOptions in the JavaScript Reference for available options

 

  // Set the options you want below:

 

 

  // For example, uncomment to set the compatibility of the generated pdf to Acrobat 7 (PDF 1.6)

  // options.compatibility = PDFCompatibility.ACROBAT7;

 

  // For example, uncomment to view the pdfs in Acrobat after conversion

  // options.viewAfterSaving = true;

 

  return options;

}

 

 

/** Returns the file to save or export the document into.----------------CHANGE FILE SUFFIX ON LINE BELOW, var newName = ------------------

  @param docName the name of the document

  @param ext the extension the file extension to be applied

  @param destFolder the output folder

  @return File object

*/

function getTargetFile(docName, ext, destFolder) {

  var newName = "_HR";

 

 

  // if name has no dot (and hence no extension),

  // just append the extension

  if (docName.indexOf('.') < 0) {

  newName = docName + ext;

  } else {

  var dot = docName.lastIndexOf('.');

  newName = docName.substring(0, dot)+newName;

  newName += ext;

  }

 

  // Create the file object to save to

  var myFile = new File( destFolder + '/' + newName );

 

  // Preflight access rights

  if (myFile.open("w")) {

  myFile.close();

  }

  else {

  throw new Error('Access is denied');

  }

  return myFile;

}

How to rotate a art board in a illustrator using adobe extended javascript

$
0
0

How to rotate a art board in a illustrator using adobe extended javascript

 

how to create mirror image of each textframe content of artboard

Open File in RGB mode

$
0
0

How to Open file in RGB mode in illustrator using Javascript

AbsoluteURI doesn't seem to work

$
0
0

Attempting to use absoluteURI on a Folder selectDlg or a File saveDlg and I can not get an absolute path - I always return this: ~/Desktop/tmp00000001
Which doesn't work. I'm using node.js and the fs system which won't accept the output of Extendscript.

 

Anyone have any good ideas? I'd post over on the Extension forum, but it's deader than a doornail.

 

function chooseExportFolder () {

    var myLocFolder = new File("~/Desktop").saveDlg("Enter a prefix for Export(s).");

    return myLocFolder.absoluteURI;

}


Executing HTML file in Yosemite

$
0
0

SO, as of Yosemite on Mac, doing a file.execute() on an html file is broken.  The browser opens a document, but the URL is all screwed up, it says something like file:///.file/id=6571367.2773272/

See similar issue in a different field: https://bugreports.qt.io/browse/QTBUG-40449

 

Is there anything that can be done?

X,Y coordinates are printed wrong on the Second ArtBoard

$
0
0

Hi All,

 

I'm new to the illustrator scripting.

But out of my one month exposure to the scripting have explored plenty of things and started my project of writing script to print X,Y coordinates of different objects in an ai file.

 

My ai file would have different artboards and only for one artboard my script is properly printing the X,Y coordinates properly.

For all other artboards it is taking the coordinate system from the ai file and hence printing wrong.

 

Can somebody help me to sort this issue out.

Below is my script.

 

 

I couldn't attach the .ai file, with this, happy to share my sample file which I am trying to run the script.

Please correct me what is wrong in my script.

// Create an empty dialog window near the upper left of the screen

var dlg = new Window('dialog', 'Design Layout ');

dlg.frameLocation = [100,100];

dlg.size = [250,300];

 

dlg.intro = dlg.add('statictext', [20,20,150,50] );

dlg.intro.text = '"Select 1 (or) more items"';

 

var touchAreaCheckBox = dlg.add ("checkbox", [20,50,150,70], " Touch Areas");

dlg.GenerateButton = dlg.add('button', [20,170,150,200], 'Generate', 'CenterCoord');

 

// number of decimal places

var decimals = 0;

 

// document

var doc = activeDocument;

 

function generateDimensions()

{

       var totalLayers = doc.layers.length;                               

              createLayer('Touch Area Coordinates');

               for ( var i = 0 ; i < totalLayers ; i++)

                          {

                                            var currentLayer = doc.layers[i];  

                                            if (currentLayer.name == "Touch Areas")

                                            {

                                                 currentLayer.hasSelectedArtwork = true;

                                                 break;

                                            }

                                            else

                                            {

                                                 //TO DO

                                            }

                                       

                                //Unlock the layer if needed

                                currentLayer.locked = false;

                             }  

                  getLeftCoord();

}

 

function createLayer(layerName)

{

                                 try

                                {

                                     var speclayerCenter =doc.layers[layerName];

                                }

                                catch(err)

                               {

                                    var speclayerCenter = doc.layers.add();

                                    speclayerCenter.name = layerName;   

                               }

   

}

 

 

// measurement line color

var color = new RGBColor;

color.green = 255;

color.blue = 0;

 

/**

  Start the spec

*/

 

function getLeftCoord()

{

    $.writeln(" doc.selection.length:::::",doc.selection.length);

   for (var iSelectedItems=0; iSelectedItems<doc.selection.length; iSelectedItems++)

   {

      

        

                                 var topLeftPosDoc= doc.selection[iSelectedItems].position;                               

                                 // To get the center coordinates

                                 var topLeftPosArt = doc.convertCoordinate (topLeftPosDoc, CoordinateSystem.DOCUMENTCOORDINATESYSTEM, CoordinateSystem.ARTBOARDCOORDINATESYSTEM);

                                 var cenPosArt = topLeftPosArt;

                                 cenPosArt[0] = topLeftPosArt[0] + doc.selection[iSelectedItems].width * 0.5;

                                 cenPosArt[1] = Math.abs(topLeftPosArt[1] - (doc.selection[iSelectedItems].height * 0.5));

                                 //specLabel(concatenate(cenPosArt[0],cenPosArt[1]),(topLeftPosDoc[0]+doc.selection[iSelec tedItems].width * 0.5),(topLeftPosDoc[1] - (doc.selection[iSelectedItems].height * 0.5)));

                                

                                // To get the bottom left coordinates

                                var bottomLeftPosArt= doc.convertCoordinate (topLeftPosDoc, CoordinateSystem.DOCUMENTCOORDINATESYSTEM, CoordinateSystem.ARTBOARDCOORDINATESYSTEM);

                                bottomLeftPosArt[1] = Math.abs(bottomLeftPosArt[1] - (doc.selection[iSelectedItems].height ));

                                specLabelGreenForLeftCoord(concatenate(bottomLeftPosArt[0],bottomLeftPosArt[1]),topLeftPo sDoc[0]+10, (topLeftPosDoc[1]- doc.selection[iSelectedItems].height));

}

  dlg.close ();

}

 

function concatenate (value1,value2)

{

var  v1 = value1;

var v2 = value2;

v1 = v1.toFixed (decimals);

v2 = v2.toFixed (decimals);

var result = v1 +" ,"+ v2 ;

return result;

}

 

function specLabelGreenForLeftCoord( val, x, y)

{

     var t = doc.textFrames.add();

  t.textRange.characterAttributes.size = 12;

         var redColor = new RGBColor();

         redColor.red = 0;

         redColor.green = 255;

         redColor.blue = 0;

         t.textRange.characterAttributes.fillColor = redColor;

  t.textRange.characterAttributes.alignment = StyleRunAlignmentType.center;

  var v = val;

        t.contents = v;

  t.top = y;

  t.left = x ;

  return t;

 

}

 

dlg.GenerateButton.addEventListener ('click', generateDimensions);

dlg.show();

visibility variable get lost on undo/redo.

$
0
0

Hello All,

 

I've scenario where I've to distinct the page items and apply some sort of unique Ids to them. So for that, I added the visibilityVariable to the page items. Code is as follows,


var idoc = app.activeDocument; 

var ipath = app.selection[0];

var idocvar = idoc.variables.add();

idocvar.kind = VariableKind.VISIBILITY; 

idocvar.name = "0001"

ipath.visibilityVariable = idocvar;

 

Everything work fines untill I used undo/redo. The visibility variable got lost on undo/redo.

 

Following are the steps that I do,
- Create a pageItem, let's say a rectangle, and select it.

- Now run the script.

- You can see in the Variables palette that variable is assigned to the object.

- Now move the page item (2-3 times) from one position to another.

- Now Undo/Redo by usnig cntrl-z and cntl-shift-z. Object get lost and there will be no variable attached to the pageItem.

 

Am I missing something here? Do we have another way to distinct the pageItems apart from visiblityVariable which will work in undo/redo case?
Thanks for any help..

Move object/group to absolute x,y coordinates

$
0
0

Hello again, all.

 

I've found an answer to this question long ago, but i can't seem to find it again and i'm not really finding anything in the documentation. How can i move an object to predefined x,y coordinates? I seem to remember something about transformation matrices?

 

As far as I can tell, the bounds and/or left/top coordinates are read-only and insertion location only refers to ZOrder?

 

any help at all would be greatly appreciated. Thanks. =)

How to change the document units of measure

Viewing all 12845 articles
Browse latest View live


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