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

Select all the objects in active artboard

$
0
0

Hi

i want to select all the objects in active artboard using javascript

anyone please help me with script

 

Thank you

Appu


List missing fonts in Illustrator

$
0
0

Hi all,

 

I've been working on a script to try and build a list of font's that not loaded in Illustrator. I know that Illustrator will alert missing fonts when a document is opened but this routine will be part of a larger script that will have the user dialogs turned off. My process is to build a list of fonts that are available to the the application, then build a list of fonts that are used within the active document and cross reference them to see if there are document fonts that are not in the application fonts list.

 

I have used a great function that I believe was posted originally by Moluapple and with some some brilliant advice from the always helpful CarlosCanto I thought that I had found the soultion but it appears to have some limitations. If I get a list of fonts available to the application and the document that I want to cross reference them against is open, the list that's returned contains fonts that are used in the document. Then when I get a list of fonts used in the document and cross reference them they will all be in the application list regardless of whether they're loaded or not.

The only way that I can get accurate results are if I run the script without any documents open and build a list of application fonts, then open a document and build a list of document fonts and then cross reference. This is the only way I can find out what fonts aren't loaded.

 

Does anybody know of another way to build a list of missing fonts without having to close documents first? I have searched through the XMP data and this doesn't seem to give me any clues and I've tried writing the code in applescript but it appears to work in the same way. Any help or comments would be welcome.

 

Here's my code:

 

#target illustrator

 

 

var doclist = app.textFonts

 

 

var appFontList = new Array ();

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

    var fontName = app.textFonts[i].name;

    appFontList[i] = fontName;

    }

 

 

var myfile = File.openDialog ('Choose a file');

app.open (myfile);

 

 

var docFontsList = getUsedFonts(activeDocument);

 

 

// function accredited to Moluapple

 

 

function getUsedFonts (doc ){

     var xmlString = new XML(doc.XMPString);

     fontsInfo = xmlString.descendants("stFnt:fontName");

     var ln = fontsInfo.length(), arr = [];

     for (var i = 0; i<ln; i++){arr.push(fontsInfo[i])};

     return arr;

}

 

 

var missingFontsList = checkFonts();

alert(missingFontsList);

 

 

function checkFonts(){

    var fontArray = new Array ();

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

        var thisDocFont = docFontsList[i];

        var activeFont = false;

        for (j = 0; j < appFontList.length; j++){

            var thisAppFont = appFontList[j];

            if (thisDocFont == thisAppFont){

                activeFont = true;

                }

            }

        if (activeFont == false){

            fontArray.push (thisDocFont);

            }

        }

    return fontArray;

    }

 

 

Many Thanks,

Nik

change the strokewidth of all the items on the page.

$
0
0

Hello!

My goal with this script is to update all of the items on the page of an SVG file so that they have a stroke width of .2 and the color is grey.

 

All of the objects turn the correct color of gray. (Working as intended....Yay!)

 

However, only SOME of the objects change to the correct width with this script.

 

When I open the SVG file manually and use CTRL-A (select all on windows) and then change the stroke width setting, it comes out perfect.

 

This functionality is what I"m trying to replicate with my script.

 

app.userInteractionLevel =UserInteractionLevel.DONTDISPLAYALERTS;
var doc = app.activeDocument;

for( i =0; i <doc.pathItems.length; i++){
pathArt
= doc.pathItems[i];
pathArt
.strokeWidth =.2; //some of the paths do not change to .2. They DO change when manually 'selecting all' without the script.
pathArt
.strokeColor = makeColor(153,153,153); //works fine
pathArt
.filled =false;
}

 

//function for changing color. This function works fine.
function makeColor(r,g,b){
var c =newRGBColor();
c
.red  = r;
c
.green = g;
c
.blue  = b;
return c;
}

 

How to exit the script?

$
0
0
How do I terminate the script - not Adobe application(s)?
exit(), quit()... - they don't work.

The only workaround I can think of is a main() function with "returns" in appropriate places, but I am just curious if there is a terminating command.

moniuch

script to batch rename/number layers in Illustrator CS6

$
0
0

Is there a script that I can use in Illustrator to batch rename all sub-layers? I would also like to be able to add sequential numbers to each layer too. I saw an older post that contained a script to do this but it seemed outdated and doesn't work on CS6. Here it is for reference, maybe someone can modify it to work for CS6?

 

////START SCRIPT////

docRef=app.activeDocument;
topLayers=docRef.layers;
for(i=0;i<topLayers.length;i++){
var currLayer=topLayers[i];
var newNum=i+1;
currLayer.name="Layer "+newNum;
subLayers=topLayers[i].layers;
for(j=0;j<subLayers.length;j++){
  var currSubLayer=subLayers[j];
  var newSubNum=j+1;
  currSubLayer.name="Layer "+ newNum+"."+newSubNum;
  subSubLayers=subLayers[j].layers;
   for(k=0;k<subSubLayers.length;k++){
    var currSubSubLayer=subSubLayers[k];
    var newSubSubNum=k+1;
    currSubSubLayer.name="Layer "+ newNum+"."+newSubNum+"."+newSubSubNum;
   }
  }
}

////END 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

Need a way to hide a layer in a document from UI

$
0
0

Hi experts,

 

I have a requirement to add a Text to layer and make it uneditable to user.

 

I have successfully tried to Lock, hide, diable edit layers as well as textFrame inside the layer via Scripting. However in Illustrator UI,  when user opens the document, user has the option to make the layer or Frame editable which is locked by scripting..

 

So, looking for an option to lock, hide the layer via Scripting and also have no option for user to unlock or make visible  from UI.

 

 

Here is the code I used:

 

// Finds the tags associated with the selected art item,

// show names and values in a separate document

if ( app.documents.length > 0 )

{

    doc = app.activeDocument;

    if ( doc.selection.length > 0 )

    {

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

            {

                        selectedArt = selection[0];

                        tagList = selectedArt.tags;

                        if (tagList.length == 0)

                        {

                                var tempTag = tagList.add();

                                tempTag.name = "OneWord";

                                tempTag.value = "anything you want";

                         }

             }      

        // Create a document and add a line of text per tag

        var reportDocument = app.documents.add();

        top_offset = 400;

      

        for ( i = 0; i < tagList.length; i++ )

        {

                    tagText = tagList[i].value;

                    newItem = reportDocument.textFrames.add();

                    newItem.contents = "Tag: (" + tagList[i].name +

                    " , " + tagText + ")";

                    newItem.position = Array(100, top_offset);

                    newItem.enableAccess = false;

                    newItem.editable = false;

                    newItem.locked = true;

                    newItem.hidden = true;

                    newItem.layer.visible = false;

                    newItem.layer.opacity = 0;

                    newItem.layer.preview = false;

                    newItem.layer.locked = true;

                    newItem.layer.enable=false;

                    newItem.layer.requirePermissionPassword = true;

                    newItem.layer.permissionPassword = "Vinnudear";

                    newItem.textRange.size = 24;

                    top_offset = top_offset - 20;

                   // newItem.layer.parent.save();

        //newItem.layer.parent.saveNoUI("c:\\temp\\LockTest.ai");

        //newItem.layer.parent.requirePermissionPassword = true;

        //newItem.layer.parent.permissionPassword = "teamcenter";

        newItem.note = "USER:VINAY";

        alert(newItem.note);

        } 

    }

}

 

Regards,

Vinay

 

Message was edited by: Vinay Seera

Swapping fill and stroke on multiple objects

$
0
0

Wondering if there's a script out there that will automate the swapping of fill and stroke for multiple objects in a complex image. Doing it object-by-object is a bit tedious (even using 'select similar' commands).

 

A simplified example: I have four solid filled boxes with no stroke, each box a different color. Can I automate switching stroke and fill on each one so I end up with four non-filled boxes, each stroked with their former fill color? Perhaps there's a way to automate the sequential selection of each object and perform the swaps one at a time.

 

Thanks for any advice!


Assigning Text Fields Variables via VBScript

$
0
0

I'm looking to complete the first challenge of my project of repopulating text fields with translated text automatically.  To do this I need to pull the text down from an Ai file.  However, each text field must be identifiable so that it can be recorded into an excel spreadsheet.  So the spreadsheet would essentially contain the following data:

 

Column 1

 

File Name + Text1(this being variable name)

 

Column 2

 

English text pulled from that variable text field

 

Column 3

 

Translated text

 

So I need to code a script to batch through a folder of Ai files and assign each text field in the drawing a unique identifier or variable, i.e. "Text1", "Text2", etc...

 

I know that I can convert a text field to dynamic flash text which allows me to manually name a field, however doing this through script is less obvious to me, any help would be apreciated!

 

Furthermore, if there is already a unique identifier on textfields by default that I can tap into, that would be nice as well.  Otherwise I'd like to write a script that in the beignning of the code it steps through the number of fields and assigns each a unique identifier, copies that identifier to a spreadsheet, then next to that, copies in the text from the field into the spreadsheet as well.

 

Thanks,

-Chris

Why illustrator allowed pathItem store error msg?

$
0
0

So this happen, I cycle through my artwork, compare their typename ono by one, and my script keep crushing.

Turns out there is often one or two pathItem's object tree property completely lose their mind.

No property, but error msg like this image, and this happens so often.

How do I copy the path name from the layers panel to the center of the path/object in my AI file? Is there a native function or some sort of scripting that could be done?

$
0
0

For Instance, I have a map of the United States.  Each state is a path and has been named in the Layers Panel.  I now want to generate the state name from the layers panel so it is automatically centered text in each path/state.  Each file will also be saved as an svg once finished.  I want to to do this so that it saves me time from having to manually type each state name in the state.

How to call a swatch from the library

$
0
0

Hi,

 

I'm writing a script to create a new AI document with a restricted swatchbook. The designer is supposed to use only the swatches/inks provided by this script.

So far I was able to delete all current swatches and add a CMYK or RGB spotcolor swatch.

 

var inkt02 = app.activeDocument.spots.add();

inkt02.name = 'inkt 2';

inkt02.colorType = ColorModel.SPOT;

var kleur02 = new CMYKColor();

kleur02.black = 10;

kleur02.cyan = 80;

kleur02.magenta = 0;

kleur02.yellow = 90;

inkt02.color = kleur02;

var newSpotColor = new SpotColor();

newSpotColor = inkt02;

newSpotColor.tint = 100;

thePallet.addSpot(newSpotColor);

 

Often we will be dealing with Pantone colors. No need to define these, as they are inside AI already, right? But how to call them from the library?

 

I'm new to ExtendScript, but this forum (and google) helped me along nicely so far :-)  I don't have a concrete use case for this yet, but I decided on this exercise as a good way to learn about ExtendScript.

Illustrator script.

$
0
0

here I have already retrieved nonNativeItems,below that JSON data is there, using this JSON data again how to re create the nonNativeItems in illustrator.

 

 

var page_details = { 

"full_name": "C%3A%5CUsers%5CAdministrator%5CAppData%5CRoaming%5CSkype%5CMy%20Skype%20Received%20Files %5C324580-1.ai",

"name": "324580-1.ai",

"page_count": 1,

"height": 15.0098402235243,

"width": 10.3500027126736,

"top": 15.0098402235243,

"left": 0,

"modification_on": "2017-07-04 09:55:51",

"creation_on": "2017-07-04 09:55:36",

"pages": [{

  "page_number": 1,

  "top": 15.0098402235243,

  "left": 0,

  "width": 10.3500027126736,

  "heigth": 15.0098402235243

}]

 

}

var selected_area = {

"arrSelectedArea": {

  "noe": 3,

  "xpos": 9.01471625434028,

  "ypos": 13.7328694661458,

  "height": 12.6598239474826,

  "width": 0.86028374565972,

  "pageNo": 1,

  "preview": "selectionareaexportimage1"

},

"arrCompoundPathItem": [

 

],

"arrImageFrames": [

 

],

"arrGraphItems": [

 

],

"arrLegacyTextItems": [

 

],

"arrMeshItems": [

 

],

"arrNonNativeItems": [{

  "xpos": 0,

  "ypos": 0.53643120659722,

  "styleJSON": "{\"controlBounds\":\"[648.0595703125,951.1435546875,712,949.1435546875]\",\"editable\":t rue,\"geometricBounds\":\"[649.0595703125,950.1435546875,711,950.1435546875]\",\"hidden\" : false,\"left\":649.0595703125,\"locked\":false,\"name\":\"\",\"opacity\":100,\"position\" : \"[649.0595703125,950.1435546875]\",\"sliced\":false,\"top\":950.1435546875,\"typename\": \ "NonNativeItem\",\"visibilityVariable\":null,\"visibleBounds\":\"[649.0595703125,950.1435 5 46875,711,950.1435546875]\",\"wrapInside\":\"\",\"wrapped\":false,\"wrapOffset\":\"\",\"a r r_position\":0}",

  "height": 0,

  "width": 0.86028374565972,

  "index": null,

  "layer": "Layer 1",

  "layer_info": "{\"name\":\"Layer 1\",\"layerName\":\"Layer 1\",\"typename\":\"Layer\",\"opacity\":100,\"visible\":true,\"dimPlacedImages\":false}",

  "groupName": "",

  "arr_position": 0

}],

"arrPluginItems": [

 

],

"arrRasterItems": [

 

],

"arrShapes": [

 

],

"arrSymbolItems": [

 

],

"arrTextFrames": [

 

],

"arrTextElements": [

 

],

"arrGroups": [

 

]

}

Save Options in Illustrator Scripts

$
0
0

Hello,

 

I am looking for documentation for Illustrator Scripts. I would like to create several scripts that will export folders of files to other formats. I found a script for PNG export, however do the following options exist for JPG as well?

 

/********************************************************* getPNGOptions: Function to set the PNG saving options of the  files using the PDFSaveOptions object. **********************************************************/    function getPNGOptions()  {            // Create the PDFSaveOptions object to set the PDF options      var pngExportOpts = new ExportOptionsPNG24();                        // Setting PNGExportOptions properties. Please see the JavaScript Reference      // for a description of these properties.      // Add more properties here if you like      pngExportOpts.antiAliasing = true;      pngExportOpts.artBoardClipping = true;      pngExportOpts.horizontalScale = 200.0;      //pngExportOpts.matte = true;      //pngExportOpts.matteColor = 0, 0, 0;      pngExportOpts.saveAsHTML = false;      pngExportOpts.transparency = true;      pngExportOpts.verticalScale = 200.0;        return pngExportOpts;  } 

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;

}


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

Create Artboard by looping through specific path items

$
0
0

I am need of a script where I can convert the "thru-cut" layers into artboards. I am horrible at creating loops and honestly not sure if it is possible to loop "thru-cut" one at time to create an artboard. Below are screen shots of what I am trying to do. Thanks for your help ahead of time.

Using excel data in illustrator

$
0
0
I'm a Corel user who has a task that may require migrating to
Illustrator. I'd like to know if this can be done.

I may need to maintain a map for a community project. On this map, we
have a tree inventory, and we have a fairly extensive Excel data set
(including, in the near future, GPS data).

I would _like_ to be able to take the data in the spreadsheet, and have
my graphics program place symbols on the map depending on the data. And
if I change the data, the map changes.

For example. Let's say the Excel spreadsheet includes values for the
tree name, its Latin name, its age, its height, canopy width, and
GPS-derived latitude and longitude. Is there a way to hotlink this data
to an Illustrator file, so that a) a circle is drawn at its latitude and
longitude, b) a symbol depicting the tree's canopy is drawn in
proportional size, c) a text label appears nearby with the name and/or
Latin name? And if I add trees to this spreadsheet, they will
automatically be added to the map?

Importing Latitude and Longitude Data into Illustrator CS6

$
0
0

It is possible to convert a PDF MAP into a Illustrator MAP with Actual Latitude and Longitude data a POI ( Place of Interest) Or Create a POLYLINE like you do in Google maps and Feed the GPS data into Illustrator and It will create the Exact same shape of the LINE .

Illustrator VBA scripting 101 - via Excel

$
0
0

This post will attempt to introduce newcomers to Illustrator Visual Basic Scripting (well, not actually vbs, but rather tru VBA, Visual Basic for Applications). I personally prefer vba over bvs for a number of reasons. First, I always have Excel and Illustrator open, so it makes sense for me use it to drive Ai. Second, I usually need to transfer data between the two programs. Third...I love the Excel IDE...ok, let's get right into it.

 

 

- Open Excel

- hit Alt+F11, to bring up the editor

- in the Tools menu, click on References...

- add a reference to "Adobe Illustrator CS5 Type Library"

- in the Personal.xls (or in any other book) add a Module. Personal is a global workbook that is always available. If you don't see it, go back to Excel and record a macro, anything will do. That will create the Personal file.

- and type the following in that module

- we have to continue the tradition and do the "HelloWorld" script

 

Sub helloWorld()    Dim iapp As New Illustrator.Application    Dim idoc As Illustrator.Document    Dim iframe As Illustrator.TextFrame       Set idoc = iapp.ActiveDocument    Set iframe = idoc.TextFrames.Add       iframe.Contents = "Hello World from Excel VBA!!"       Set iframe = Nothing    Set idoc = Nothing    Set iapp = Nothing
End Sub

 

- save Personal book

- open Illustrator and create a new document first

- to run, move the cursor anywhere inside the Sub...End Sub and hit F5

 

that's it for now...in the following posts we'll move the text to the middle of the page, create new documents, get data from an Excel Range to Illustrator, get data from Illustrator text frame to an Excel Range...and more, hopefully.

 

questions? comments?

Viewing all 12845 articles
Browse latest View live


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