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

Deleting file from Hot Folder

$
0
0

I have a script that is running a series of commands triggered from a file in a hot folder...

 

I'm trying to delete the original file from the IN folder once the script is done...

 

What' I've tried is not working... Any Ideas...

 

var delfo = Folder ( '~/Desktop/Illustrator Hot Folder/11 x 8.5 Proof/In' ); 

var delfiles = delfo.getFiles (); 

 

delfiles.remove();


add page numbers via script

$
0
0

I want to try to add page numbers to artboard based on position of selected text. I saw someone had made a script similar to this, but I need to do it based on selected text. Here is my solution, but for some reason it is not adding it based on artboard coordinates. I ran into this a while ago, and setting the rule to artboards fixed it, here it does not seem to have same effect.

 

#target illustrator
// global variables

////////////////////////////////////////////////////
// Set up varaibles
////////////////////////////////////////////////////


var pageNumber = app.activeDocument.artboards.getActiveArtboardIndex() + 1,
    doc = app.activeDocument;


//make sure only 1 item is selected
if(selectedItems.length > 1 || selectedItems.length < 1) {    alert('please select only one item'}
else {    var selectionTopPosition = doc.selection[0].top,        selectionLeftPosition = doc.selection[0].left;    doc.selection[0].remove();    doc.selection = null;    //remove selection    //alert(selectionLeftPosition+" "+selectionTopPosition);
}


//create page numbers layer
var pageNumbersLayer = doc.layers.add();
pageNumbersLayer.name = "page numbers";
var pageNumbersLayerGroup = pageNumbersLayer.groupItems.add();


// main loop
//loop through artboards
for(i = 0; i < app.activeDocument.artboards.length; i++){    app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;    doc.artboards.setActiveArtboardIndex(i);    alert('active artboard is '+i);    var pageNumber = doc.artboards.getActiveArtboardIndex() + 1;    var pageCount = i + 1;    var textRef = pageNumbersLayerGroup.textFrames.add();    textRef.contents = pageCount.toString();    textRef.top = selectionTopPosition;    textRef.left = selectionLeftPosition;    pageCount++;
}

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!

Change a font using extendscript in illustrator

$
0
0

I have a script that loops through text items on an illustrator page and when it encounters one of a certain size it changes it to a different point size. I would also like to alter the font. The code I have is

 

     if (roundedSize== 7.2) {

                item.textRange.characterAttributes.size=9.6;

                $.writeln(item.textRange.characterAttributes.textFont)

                item.textRange.characterAttributes.textFont="Metric-Semibold"

                };

 

It work fine without the fourth line, but as soon as I try and set a typeface the loop bails. Could someone tell me what I am doing wrong here

 

Many thanks

Change font in Illustrator cs4 js

$
0
0

I need to assign specific font to my text and it doesn't work. What am I doing wrong:

 

 

var my_OUTSIDE_TextFrame = myInstrLayer.textFrames.add();
my_OUTSIDE_TextFrame.geometricBounds = ["1.6 in", "1 in", "1.85 in", "2.75 in"];
my_OUTSIDE_TextFrame.contents = "OUTSIDE";

var myParagraph = my_OUTSIDE_TextFrame.paragraphs.item(0);
try{
myParagraph.appliedFont = app.fonts.item("Myriad Pro");

}
catch(e){}
try{
myParagraph.fontStyle = "Bold";
}
catch(e){}

myParagraph.pointSize = 30;

 

And it's not placing it where I want it either.

 

Thank you very much for your help.

Yulia

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!

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

Image trace in js script

$
0
0

Hi!

I'm trying to trace a PNG image in Adobe Illustrator via js script. I've tried different approaches, but always have the same problem - I can't change Color setting automatically. Here is my simple script:

thisImage.tracing.tracingOptions.tracingMethod = TracingMethodType.TRACINGMETHODABUTTING; 
thisImage.tracing.tracingOptions.tracingMode = TracingModeType.TRACINGMODECOLOR; 
thisImage.tracing.tracingOptions.cornerFidelity = 50; 
thisImage.tracing.tracingOptions.pathFidelity = 55; 
thisImage.tracing.tracingOptions.noiseFidelity = 5; 
thisImage.tracing.tracingOptions.maxColors = 40; 
thisImage.tracing.tracingOptions.colorFidelity = 50; 

app.redraw();

So other parameters were changed during this script execution (Paths, Corners, Noise), but Colors is 100 again despite maxColors and colorFidelity. And I don't see any additional fields in tracing options that can be responsible for this.

%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA.PNG

Could you please give me any advise how to solve this issue?


Check for the existence of an expected element

$
0
0

Hello again, scripters!

 

I'm looking for a solution to a problem that has plagued me for quite some time.. In order to make my scripts more robust and less prone to failure, i spend a lot of energy writing test conditions to make sure that an expected element actually exists in the document. Now, this element could be a groupItem or a textFrame or a layer.. Basically anything.

 

The syntax I wish i could use is this:

if(docRef.layers["someLayer"].exists)

     {//do something}

else

     {//do something else}

 

But unfortunately "exists" is not a property of layer/groupItem/textFrame etc.

 

A quick example, since this happens to be what I was working on when i decided to write this post. I like to put stuff into a file upon completion of a task so that at runtime, i can check to see whether said process has already been completed and then determine whether to proceed or not. Perhaps there are better methods, but i typically create specifically named sublayers to indicate a task has been completed. Unfortunately, however, the checks become quite convoluted in order to avoid runtime errors for "no such element".

 

How do you guys check that an important element exists so you can be sure to proceed appropriately? My method seems to always go back to try/catch blocks that can sometimes end up really ugly looking. I think I'm at the point of writing myself an abstract function that I can call whenever I need it, but i wanted to see how you guys handle similar issues before i invest the time into writing something potentially unnecessary.

 

Thanks in advance everyone. =)

Change Folder.current to location of script (.jsx) file?

$
0
0

All,

 

I'm trying to use some images in my ScriptUI dialog, but I want to use a "relative" path name, and I can't seem to get it to work.

For example, this myScript.jsx works just fine, but as you can see, I'm using an "absolute" path name to transparencyGrid.jpg:

 

var w = new Window ("dialog");
var f = new File ('~/Desktop/transparencyGrid.jpg');
w.add ("image", undefined, f);
w.show ();

 

However, I want to be able to use a relative (to myScript.jsx) path to point at transparencyGrid.jpg, like this:

 

var w = new Window ("dialog");
var f = new File ('../../../transparencyGrid.jpg');
w.add ("image", undefined, f);
w.show ();

 

But, I can't seem to get this to work because relative paths seem to be relative to the current folder, Folder.current, not the location of the currently executing script.

I say that because when I do this:

 

alert(Folder.current);

 

The only thing the alert message shows is a backslash (/), indicating to me that the current folder is the root of my OS, but I thought it would be the folder where myScript.jsx resides.

 

So, is there a way of setting Folder.current to the location of the actual script?

Resize Artboard to exact size : jscript

$
0
0

Hello

 

I'm trying to resize my artboard to an exact mm size via a script so then I can add this to a batch i'm trying to achieve.

 

I've been trying to use the following, but i cant work out how to add the size I want in mm?

 

Any help?

 

Thanks

 

#target illustrator

 

var doc = app.activeDocument;

 

var docVB = doc.visibleBounds;

    var myVisibleBounds = doc.visibleBounds; //Rect, which is an array;

    myVisibleBounds[0] -= 20; //left coordinate (use negative values to add artboard)

    myVisibleBounds[1] += 20; //ltop coordinate

    myVisibleBounds[2] += 20; //right coordinate

    myVisibleBounds[3] -= 20; //bottom coordinate (use negative values to add artboard)

    doc.artboards[0].artboardRect = myVisibleBounds;

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?

[ANN] New Extension in beta test.

$
0
0

Script Slot, It makes custom menu in Illustrators window menu and make some slot that you can set Javascript(Extendscript) and Applescript(application) file and add shortcut key combination like below.

スクリーンショット 2015-11-28 17.54.34.png

 

This beta test version supports Illustrator CC 2014/2015, OSX10.9 and later.

 

You can download it: https://goo.gl/HZ05VE

Illustrator Scripting Panel

$
0
0

Just thought I'd share an extension I've been tinkering with:

 

GitHub - majman/adobe-scripts-panel: Scripting Panel for Adobe Illustrator

 

It's a pretty simple panel that allows you to try snippets of code in the editor, list and run saved scripts from your local files, or even load and run scripts from the web.

 

Hope somebody finds it helpful. Feel free to fork the repo and send pull requests.

 

-Marshall

Is it possible to create droplet?

$
0
0
Is it possible to create a droplet in "illustrator cs"?

ESTK Data Browser Question

$
0
0

Does anyone know if the scope of the data browser (while stepping through the code) is customizable at all?

By default, it shows the local scope, showing only the variables local to the current function. Is it possible to include inherited variables in the display?

 

Specifically i'm trying to view some JSON of script global scope in the data browser so I can just peruse all the properties rather than writing a loop to display certain props.

 

Thanks in advance,

 

William.

Export to Tif

$
0
0

Hi ,

 

While export to Tif from illustrator using below resolution not working , instead of previous resolution takes effect.

 

 

var exportOptions = new ExportOptionsTIFF();

exportOptions.resolution =166;

app.activeDocument.exportFile(fileSpec, ExportType.TIFF, exportOptions );

Transform Each

$
0
0

Hi all,

 

i'm working on a script and final step is missing, i just want to know Transform each function code on JavaScript, or at least i want to create a code can do a shortcut like (Alt+Ctrl+Shift+D)

 

 

Object > Transform > Transform Each with Reflect X and Center point position

 

image.png

 

 

7.png

 

 

is it possible??

 

 

Thanks a lot

 

Scripting: Prompt a Dialog Box to add text to part of my existing Script.

$
0
0

     I'm new with scripting and haven't had a lot to do with it, so i'm looking for a little help. I need to add to my companies existing Script Pallet, we have a script that creates our art into dies for us. So that they can be used for Debossing/Hotstamping items. But, we need the "Die" to have the Name of the job on it, so i'm trying to get a box to prompt up to add that text to the top of my die...I have got the box to come up but i can't get it to put the text on the art. Am I missing a link somewhere?

 

var newDieName = prompt ('Enter Job Number for New Die', " ","Creating Die");

var newDieName = newDieName.name;

 

            var die_num = thisDoc.textFrames.add();

            die_num.contents = "DJ" +(newDieName)+ ".01" + "-" + " " +magThick;

            die_num.moveToBeginning(rec_group1);

       

    var myParagraph = die_num.paragraphs[0];

            myParagraph.characterAttributes.size = 12;

            myParagraph.characterAttributes.textFont=app.textFonts.getByName("MyriadPro-Regular");

            myParagraph.characterAttributes.fillColor = orange;

       

//  Determines where the die number should be placed.

     die_num.top = -170;

     die_num.left = -54;

     die_num.filled = true;

     die_num.rotate(180);

     die_num.overprintFill = false;

//  End of die number creation

;

 

Please let me know if you need any other information; i will see want i can do to.

Pause or Wait Between Commands...

$
0
0

The below is a portion of a larger script I have... What I'm wanting to do is place a Pause/Wait/Sleep (whichever is appropriate) command to wait on the item to finish printing before proceeding to the next section...

 

I've added the sleep function... but it doesn't appear to be working or is not understanding what I'm wanting it to do...

 

Any Ideas

 

 

//Print

var storeUserInteract = userInteractionLevel;

var d                 = activeDocument;

var jbOpts            = new PrintJobOptions();

var opts              = new PrintOptions();

opts.printPreset      = "JEFF_HP";

opts.jobOptions       = jbOpts;

userInteractionLevel  = UserInteractionLevel.DONTDISPLAYALERTS;

d.print(opts);

userInteractionLevel = storeUserInteract;

 

 

$.sleep (10000);

 

 

//Through Cut Backward

function wrapper()

{

     var docRef = app.activeDocument;

     var layers = docRef.layers;

     var artLayer = layers["Artwork"];

     var thruCutLayer = layers["Through Cut"];

   

     function bringThruCutForward()

     {

          thruCutLayer.zOrder(ZOrderMethod.BRINGTOFRONT);

     }

     function sendThruCutBackward()

     {

          thruCutLayer.zOrder(ZOrderMethod.SENDTOBACK);

     }

 

     sendThruCutBackward();

}

wrapper();

Viewing all 12845 articles
Browse latest View live


Latest Images

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