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

script to align selected objects to artboard

$
0
0

Hello, I was wondering if anyone had a simple solution to aligning selected items to the artboard. I was going to create an action but then realized it would be more convenient for me to include it in my script file....I have a script to align objects with each other but they dont align to the artboard. Any suggestions?


Make several artboards from objects

$
0
0

Hi everybody. I have such a problem. There are several non-overlapping objects on the artboard. I need to arrange each object on its own artboard in the same place as on the original arboard. I'd try to wrote script by myself, but I was only able to multiply artoboards by the number of objects.

Thank you in advance for your cooperation.

Untitled-1.png

Can javascript execute pathfinder commands?

$
0
0

Can javascript execute menu commands such as pathfinder options?

[Q] Illustrator seems forgeting what selected after 50 sec on Mac. How to avoid?

$
0
0

I'm not sure what's going on the detail, but it seems only on Mac with Illustrator CC 2017. Windows seems fine.

 

Currently my code is monitoring what object selected and significant performance issue on certain case.

I got workaround to work, but I'd like to know if there's better solution.

 

It is from CEP plugin JavaScript file and used CSInterface.evalScript() to call JSX.

JSX part is simple and only accessing followings:

     documents.length

     activeDocument.selection.length and typename

 

On Windows (i7 2.5GHz machine), it responds about 9 - 15 ms.

On Mac (i7 2.5GHz machine), it responds 20-40 ms. It's obviously slower than Windows.

 

But if I left for over 50 sec, it responds 2 - 30 second (not millisecond) on Mac.

Illustrator is foreground.

Second request become fast as usual.

 

My current workaround is ping above function every 10 second and avoid Illustrator forget the selection.

I tried ping with app.version instead of above selection code, so I think it's not CEP or app object part.

 

Is there any better solution?

 

Thank you,

Naoki

Renaming Sub-Layer

$
0
0

I have this tiny script to rename a Sub-layer which works the first time I use it, then it adds to the existing sub-layer name when I run it after the first time.

 

 

var docRef = activeDocument;   
var sel = docRef.selection;   
for (var i=0; i < sel.length; i++)   
     sel[i].name = "CUTTER_B" + sel[i].name;

 

 

Any way to get this to consistently rename the sub-layer?

Ai Packaging Script

$
0
0

Ok.. I'm sure this has been posted before (already searched, didn't find however), but does a file packaging script exist for AI? (one that collects all linked images and fonts and places them in one place) This would be IMMENSELY helpful to me if anyone can post a link to one or even be willing to write it.

 

OS: W7

AI Version: CS5

 

Thanks in advance!

Retrieve whats in the clipboard possible?

$
0
0

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

If so how?

Saving documents via Scripts: Get current file name and set save path/file type

$
0
0

I am writing a script that will:

 

-Make all layers invisible

-Make a layer named "background" visible

-Delete all the invisible layers

-Save the docment as an EPS file (leaving the original document untouched)

 

I am new to scripts and so have based my script by copying code from other scripts.

 

Here is my code:

 

var doc = app.activeDocument;

var name = doc.name;

 

 

var hide = function (){ // hide all layers (based on http://forums.adobe.com/thread/644267)

     var L=doc.layers.length;

     for (j=0;j<L;j++){  doc.layers[j].visible=false; }

}

hide();

 

 

// loop through all layers

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

 

 

 

 

 

              // Create the illusrtratorSaveOptions object to set the AI options

    var saveOpts = new IllustratorSaveOptions();

 

    // Setting IllustratorSaveOptions properties.

    saveOpts.embedLinkedFiles = true;

    saveOpts.fontSubsetThreshold = 0.0

    saveOpts.pdfCompatible = true

 

 

 

 

 

 

//Set up Variable to access layer name

          var currentLayer = app.activeDocument.layers[i];

 

// Loop through the layers and make the back ground layer visible

          if (currentLayer.name == "Background") {

                    docName = name + currentLayer.name+".eps";

                    currentLayer.visible = true;

                    }

 

 

}

 

 

// Delete Invisible Layers (based on http://www.cartotalk.com/index.php?showtopic=7491)

var myDoc=app.activeDocument;

var layerCount=myDoc.layers.length;

for (var ii = layerCount - 1; ii >= 0; ii--) {

    var currentLayer = myDoc.layers[ii];

    currentLayer.locked = false;

    var subCount = currentLayer.layers.length;

    for (var ss =subCount -1; ss >= 0; ss--){

        var subLayer = currentLayer.layers[ss];

        subLayer.locked = false;

        if (subLayer.visible == false){

            subLayer.visible = true;

            subLayer.remove();

            }

        }

    if (currentLayer.visible == false){

        currentLayer.visible = true;

        currentLayer.remove();

        }

    }

 

// Save Out Document with New Name

 

var saveName = new File ( doc.path + "/" + docName );

doc.saveAs( saveName, saveOpts );

 

 

 

Everything works fine except:

1) It saves the document with the name AdobeIllustratorBackground as opposed to the name of the document

 

Also, I am not sure how to tell the script to save as EPS and to specify the save location.

 

Could some one give me some pointers?          Thanks!


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

Split Text into Layers

$
0
0

I was wondering if anyone is aware of a script that is able to do the same as this photoshop one http://www.agasyanc.ru/text-splitter, I would use that one in photoshop but its not working in CS6.

 

I  was hoping to find a script that will seperate the text into layers  ready for export to After Effects to be used in Kinetic Typography  pieces

 

thank you

JavaScript to prompt user to save as PDF

$
0
0

I am making changes with code to the file. I want the user to be prompted to save as a .ai file first. I have that down. Now I am wanting to have the user immediately be prompted to save as a pdf with only the optimize for fast web view option selected. I believe it is an adobe preset of Smallest File Size.

The reason for wanting the prompt is because I want to save the files in 2 different locations.

Here is my code so far.....

var doc = app.activeDocument;
// Save as .ai file 
var fileName = doc.fullName; 
var thisFile = new File(fileName);
var saveFile = thisFile.saveDlg();
doc.saveAs (saveFile);


// Save as .pdf file
var pdfSaveOptions = new PDFSaveOptions(); 
pdfSaveOptions.pDFXStandard=PDFXStandard.PDFXNONE; 
pdfSaveOptions.compatibility = PDFCompatibility.ACROBAT5; 
pdfSaveOptions.preserveEditability = false;  
var pdfFile = new File(fileName); 
doc.saveAs(pdfFile, pdfSaveOptions);

AI CS4 Windows 7 64bit

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.

Resize Artboard

$
0
0
Unsure if Im asking in the right spot but is it possible to automate the resizing of the artboard say from A0 down to A1

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.

Convert string (string of JSON) to JSON object?

$
0
0

**EDIT**

I finally figured out how to use #include instead of file.read();. This solves my immediate problem. However I am still curious as to whether it's possible to do what I'm asking for below, just in case there comes a situation where for whatever reason I cannot simply use #include. Thanks everyone. =)

**EDIT**

 

**EDIT 2**

Anyone know how to use #include for a file whose name is determined during script execution?

For example.. the variable orderNumber is generated by a prompt window (lets say the result is 1234567). the file i want to include will be named "1234567.js).

What I want to do is something like:

#include "~/Desktop/Info Folder/" + orderNumber + ".js"

(then I want to assign a variable to the result somehow, since it's simply an anonymous object at this point and i don't know how to access it's contents);

**EDIT 2**

 

Hey all. I have a (most likely really stupid) question about how to take a string that contains the JSON text and simply change it's type from "string" to "object"... I'm probably wording this very badly.

 

I'm fetching a .js file from my local network and setting a variable to the result of file.read();

 

The contents of the file is an anonymous object in JSON. However, when i use file.read(); the object is brought in as a string, like this:

 

'{"roster":[{"name":"Fink","number":"19","jerseySize":"XL","qty":"1","topId":"78531"},{thi s is the next player},{this is the next player}]}'

 

That is a massively simplified version of what i'm actually reading, but you get the point. I want to be able to bring that object into the script that I'm running and create new objects based on the pertinent information (in this case i only need the values for "name", "number", and "jerseySize").

 

So my question is this. how do i turn the above string of JSON into:

 

var roster = [

     {

     "name":"Fink",

     "number":"19",

     "jerseySize":"XL"},

     {

     next player

     },

     {

     next player

     }

]

 

???? A google search reveals the method JSON.parse(text). But that is not supported in ESTK.


Create Fitted Artboards from layers?

$
0
0

Hey everyone,

 

Does anyone know of a script that will create artboards for each separate layer?

 

Thanks in advance,

 

Andy

Match textFrame ignoring carriage return

$
0
0

Open this file...

Document.ai - Google Drivehttps://drive.google.com/open?id=0B4ebfmBRxh3ATXBMbTUySmtpVWs

Then open this file so it is the active document...

Table.ai - Google Drive

 

I am running a script on the table I have pasted in from an Excel document. I am storing all of the names in an array.

Then it closes the table document and then searches document for matches.

The problem I am running into is that the table document is all a single line text frame and the document has text frames with carriage returns in them.

 

Here is my current code (which includes some clean up functions for odd spaces and such)....

#target illustrator
var doc = app.activeDocument;
var allText = doc.textFrames;
var componentName = [];
var theContents;


// Remove spaces that are before, after, or double
function myTrim(x) {
    return x.replace(/^\s+|\s+$/gm, '');
}


function removeDoubleSpaces() {
    var searchString = /  /g;    var replaceString = " ";    for (var i = 0; i < allText.length; i++) {        var thisTextFrame = allText[i];        var newString = thisTextFrame.contents.replace(searchString, replaceString);        if (newString != thisTextFrame.contents) {            thisTextFrame.contents = newString;        }    }
}


for (i = 0; i < allText.length; i++) {    theContents = allText[i].contents;    theContents = myTrim(theContents);    allText[i].contents = theContents;
}


removeDoubleSpaces();


// Read table data
for (var i = allText.length - 1; i >= 0; i--) {    //alert(allText[i].contents);       componentName.push(allText[i].contents);
}
//alert(componentName.length);


alert("Your component table has been successfully scanned!");
doc.close(SaveOptions.DONOTSAVECHANGES);


// Format text on Hypertext layer to read (#) Component Name
var doc = app.activeDocument;
var allText = doc.textFrames;


for (i = 0; i < allText.length; i++) {    theContents = allText[i].contents;    theContents = myTrim(theContents);    allText[i].contents = theContents;
}


removeDoubleSpaces();


var calloutStartNumber = prompt("Start with callout number...", "1", "Callout Number");




var hyperLayer = doc.layers.getByName("Hypertext");
for (var i = 0; i < componentName.length; i++) {    //alert(componentName.length);    for (var z = 0; z < allText.length; z++) {        //alert(allText.length);        if (componentName[i] == allText[z]) {            alert(componentName[i] + "  " + allText[z]);            allText[z].contents = "(" + (calloutStartNumber) + ") " + allText[z].contents;            calloutStartNumber++;        }    }
}


alert("Your components have been numbered!");

 

My desired output is Accumulator Gp - Hydraulic (Charged) is number 1 and then each item after that on the table (that is in alphabetical order) will be numbered sequentially on the document. I don't want the script to change the text box or get rid of the carriage returns....just insert the sequential number in front of it like this....

Scripting a PostScript File directly to folder no user interaction

$
0
0

Hey guys hoping you might be able to point me in the right direction here. I'm a noob at scripting Illustrator and have been racking my brain over this script for a few days now.  What i would like to achieve is creating a script that will print a Postscript file to a designated folder with no user interaction. This folder will be on an external volume but just trying to get it to a folder on my desktop at this point... so this is what i started with initially :

 

var myDoc = app.activeDocument;

 

var options = new PrintOptions();

options.printPreset="PS_print";

 

myDoc.print(options);

 

Simple, and it works except that i still have to designate the folder in which the PostScript will be saved..  so i did some digging and came across this code Muppet Mark created on a thread called " Script: print to PostScript" here Re: Script: print to PostScript .  i ran it through ExtendScript and it executed once fine only thing i need to change is where the file is saving.   So i edited it and came up with this:

 

printPostScript();

 

function printPostScript(){

    app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; 

   

    var docPath, docs, opts, psPath;

   

    jobOpts = new PrintJobOptions(); 

         

        opts = new PrintOptions(); 

          

        opts.printPreset = 'PS.print'; 

         

        opts.jobOptions =  jobOpts;

   

   

    docPath = decodeURI( app.activeDocument.fullName ); 

         

            psPath = new File( "~/Desktop/TEST" ); 

         

            jobOpts.file = File( psPath ); 

     

            app.activeDocument.print( opts ); 

     

            app.activeDocument.close( SaveOptions.DONOTSAVECHANGES );

   

   

   

     app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS; 

   

   

}

 

problem is every time i use the userinteractionLevel command illustrator throws me an error  for the line where its supposed to execute the actual printing
"app.activeDocument.print( opts );"  Or at least im assuming the userinteractionLevel command is the culprit as Illustrator throws me the same error with the script   that i started with now when it didnt before.   If any of you guys could help me out here it would be appreciated!

 

Thanks

Looking for "Replace with Symbol" script

$
0
0

So I am trying to replace gps points with a symbol I have created. I have found blogs referencing a script that can replace selected items with symbols saved in the symbols panel, but I can't seem to find the actual script! If anyone knows where I can find JET_ReplaceWithSymbol.jsx or any other script that can do the same function, it would be greatly appreciated!

Tweaking the SaveDocsAsPDF script

$
0
0
Hello. Absolute scripting newbie here; will someone take pity...?

I am looking at the SaveDocsAsPDF script. It works for our purposes except I would like it to save PDFs using a Preset we created called "SGS PDFs. (We have trouble with people in our office forgetting to choose this setting, so I thought a script might be the answer.)

I found a posting on this forum where someone wanted to save files as small as possible, and got some clues from that. So I left everything as is in the original script, except I added this first line in the function:
{var NamePreset = '[SGS PDFs]';

Then after the line:
var options = new PDFSaveOptions();

I added:
options.PDFPreset=NamePreset;

I thought this would result in a script that does the same thing I now do "manually". However, if I save my document "manually" using File/Save As/ Adobe PDF, and choosing the SGS PDFs preset (and changing nothing else), I get a 716 KB file. But if I use my script, I get a 4.9 MB file. So it appears that what I added is NOT making the script use my preset settings.

So my question is: Is there something REALLY basic missing from my script, or... In order to get a script that accomplishes everything already determined in the Preset, do I manually have to list all those settings as options?

I think I can do the latter if I need to if I just study some of the other scripts... unless there's a shortcut!
Viewing all 12845 articles
Browse latest View live


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