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

get artboard of selected item

$
0
0

I have script where I select items on multiple artboard but I can't seem to get get active art board of the selected item. Is this possible?

 

each artboard has a text item and I would like them in the same position on each of their own artboards that they are already one. right now it adjusts them all to one artboard. here is what I have so far

 

doc = app.activeDocument;
for(i = 0; i < selection.length; i++){    var firstItemPosition = doc.selection[0].position;    doc.selection[i].position = firstItemPosition;    var activeArtboardIndex = doc.artboards.getActiveArtboardIndex();    alert(activeArtboardIndex);
 }

Adding "activate some layers" to ExportDocsAsPNG24.jsx

$
0
0

I'de like to add this code

 

function test(){      function tryLockLayer(name){         try{             lrs.getByName(name).locked = false;         } catch(e) {             return;         }     };         var doc=app.activeDocument;     var lrs = doc.layers;     tryLockLayer("Watermark");     tryLockLayer("All");     tryLockLayer("Fill");     tryLockLayer("No fill");     tryLockLayer("Background");     
}   
test();


function test1(){      function tryLockLayer(name){         try{             lrs.getByName(name).visible = false;         } catch(e) {             return;         }     };         var doc=app.activeDocument;     var lrs = doc.layers;     tryLockLayer("Watermark");     tryLockLayer("All");     tryLockLayer("Fill");     tryLockLayer("No fill");     tryLockLayer("Background");     
}   
test1();


function test2(){      function tryLockLayer(name){         try{             lrs.getByName(name).visible = true;         } catch(e) {             return;         }     };         var doc=app.activeDocument;     var lrs = doc.layers;     tryLockLayer("Watermark");     tryLockLayer("Fill");    tryLockLayer("Background");     
}   
test2();            
for (i=0; i<app.documents.length; i++)     {         var idoc = app.documents[i];         //alert("+"+idoc.path+"+");         if (idoc.path == "")             {                 file = File.saveDialog ("Save file...");                 idoc.saveAs (file);             }         else             {                 //alert(idoc.name);                 if (!idoc.saved)                     {                          idoc.save();                         idoc.saved = true;                     }             }     } 

 

 

in this script

 

 

/**********************************************************

ADOBE SYSTEMS INCORPORATED
Copyright 2005 Adobe Systems Incorporated
All Rights Reserved

NOTICE:  Adobe permits you to use, modify, and
distribute this file in accordance with the terms
of the Adobe license agreement accompanying it. 
If you have received this file from a source
other than Adobe, then your use, modification,
or distribution of it requires the prior
written permission of Adobe.

*********************************************************/

/**********************************************************


ExportDocsAsPNG24.jsx

DESCRIPTION

This sample gets files specified by the user from the
selected folder and batch processes them and saves them
as PDFs in the user desired destination with the same
file name.


**********************************************************/

// Main Code [Execution of script begins here]

// uncomment to suppress Illustrator warning dialogs
// app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pngExportOpts;

// Select the source folder.
sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to PNG', '~' );

// If a valid folder is selected
if ( sourceFolder != null )
{
    files = new Array();    fileType = prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' );       // Get all files matching the pattern    files = sourceFolder.getFiles( fileType );       if ( files.length > 0 )    {        // Get the destination to save the files        destFolder = Folder.selectDialog( 'Select the folder where you want to save the converted PNG files.', '~' );        for ( i = 0; i < files.length; i++ )        {            sourceDoc = app.open(files[i]); // returns the document object                                               // Call function getNewName to get the name and file to save the pdf            targetFile = getNewName();                       // Call function getPNGOptions get the PNGExportOptions for the files            pngExportOpts = getPNGOptions();                       // Export as PNG            sourceDoc.exportFile( targetFile, ExportType.PNG24, pngExportOpts );                       sourceDoc.close(SaveOptions.DONOTSAVECHANGES);        }        alert( 'Files are saved as PNG in ' + destFolder );    }    else    {        alert( 'No matching files found' );    }
}


/*********************************************************

getNewName: Function to get the new file name. The primary
name is the same as the source file.

**********************************************************/

function getNewName()
{
    var ext, docName, newName, saveInFile, docName;    docName = sourceDoc.name;    ext = '.png'; // new extension for png file    newName = "";           for ( var i = 0 ; docName[i] != "." ; i++ )    {        newName += docName[i];    }    newName += ext; // full png name of the file       // Create a file object to save the png    saveInFile = new File( destFolder + '/' + newName );    return saveInFile;
}





/*********************************************************

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 = 100.0;    //pngExportOpts.matte = true;    //pngExportOpts.matteColor = 0, 0, 0;    pngExportOpts.saveAsHTML = false;    pngExportOpts.transparency = true;    //pngExportOpts.verticalScale = 100.0;    return pngExportOpts;
}

 

 

I need to activate some layers before export the PNG file.

Thanks

Ivan

how to place a copy of a librairie item with a script?

$
0
0

i've created a librairie with 1 graphic.

i can place this item as a embeded copy (only option available in cc 2014), or as a link (new with cc 2015)- just right click and choose the place in context menu.

 

now, how can i do this from script?

 

with this little skeleton from from the reference PDF i get access to the item from librairie in current document = so should be easy to place it as copy ...

 

 

if ( app.documents.length > 0 ) {

var fileReferences = new Array();

var sourceDoc = app.activeDocument;

var sourceName =sourceDoc.name;

 

 

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

artItem = sourceDoc.pageItems[i];

 

    switch ( artItem.typename ) {

        case "PlacedItem":

        fileReferences.push( artItem.file.fsName );

       

       

        break;

}

}

 

fred

Script for CS3 to join anchor points in 1 click

$
0
0

Hello,

Is there a script for CS3 to join many anchor points in 1 click instead of doing it corner by corner?

thanks

how to get the "pathPoints" coordinates of a textFrameItem?

$
0
0

Hi all,

 

Yes I know that textFrameItems don't have pathPoints but..

 

How can I get the x, y coordinates of the corner points of a rotated textFrameItem.

I know that I can get the angle of rotation by asin(myTextFrameItem.matrix.mValueA) etc.

My guess would be that one should be able to use the mValueTX and mValueTY to help but those values are very confusing and change dramatically on applying even a small rotation.

If anyone has some ideas preferably mathematically based and not API base please let me know.

 

It is very late by me now and I suspect I must be missing the obvious, I would think such a function must of been made.

 

Thanks

 

Trevor

 

P.s. A solution to the same problem in InDesign would also be appreciated

_2015-06-23_02-05-49.png

Javascript: Spot Colors and Inks

$
0
0
Using CS3.

Can anyone explain why Illustrator's Javascript considers any Global color a Spot Color? To see what I mean, please follow these steps:

1. Download thisthis .zip archive. It contains a small script which simply presents an alert for each Swatch in the active document, showing the swatch's name and color (type).

2. New CMYK Document. Run the Action named Delete Unused Panel Items. You should end up with only these swatches: [None], [Registration], Black, White.

3. Run the GetDocumentSwatchesInfo script. You'll see that Illustrator's Javascript considers Black and White CMYKColor, and Registration a SpotColor. So far, so good.

4. Swatches Palette flyout menu: New Swatch. Define a new swatch of any color. Make it Process.

5. Run the GetDocumentSwatchesInfo script again. Black, White, and your new swatch are CMYKColor.

6. DoubleClick your new swatch. In the Swatch Options dialog, change it from Process to Spot Color.

7. Run the GetDocumentSwatchesInfo script again. Black, White are CMYKColor; your new swatch is Spot Color.

8. DoubleClick your new swatch again. Change it from Spot Color to Process. But this time, turn on the Global checkbox.

9. Run the GetDocumentSwatchesInfo script again. Your new swatch is shown to be consider a Spot Color, despite the fact it is process.

It seems that any process swatch that I turn on as Global is considered by AI's Javascript to be a Spot Color. If you do an alert that returns app.activeDocument.spots.length, you'll see that the number of Spots includes not just spot color swatches, but spot color swatches plus global swatches.

Is this right? Looking through AICS3 Javascript Reference, I can't find anything to justify this.

Thanks to anyone who bothers to try this, and to anyone who can explain what I'm not understanding here.

JET

How to duplicate a document?

$
0
0

Hi guys,

 

I need to run a script that performs some modifications to the file, and in order to do that I would like to be working on a temp file.

 

process:

- run the script

- script duplicates file

- script runs on duplicated file

- close/dump duplicate file

 

I need help with the duplication process, i've done it before in a PSD script but the API seems to be different for Illustrator.

 

here's an AI example taken from "AI CS4 scripting reference"

 

// Duplicates any selected items from
// the active document into a new document.
var newItem;
var docSelected = app.activeDocument.selection;

if ( docSelected.length > 0 ) {     // Create a new document and move the selected items to it.     var newDoc = app.documents.add();     if ( docSelected.length > 0 ) {          for ( i = 0; i < docSelected.length; i++ ) {               docSelected[i].selected = false;               newItem = docSelected[i].duplicate( newDoc, ElementPlacement.PLACEATEND );          }     }     else {          docSelected.selected = false;          newItem = docSelected.parent.duplicate( newDoc,ElementPlacement.PLACEATEND );     }
}
else {     alert( "Please select one or more art objects" );
}

 

Now although this can be tweaked to duplicate all layers, wether selected or not, it doesn't maintain the layers.

So it duplicates all pageItems into one single layer.

 

How can i duplicate the entire Document as is with same layers and pageItems structure?

 

thanks

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!


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

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

EPS to TIFF

$
0
0

I need to export the EPS file as tiff. This option is available in Illustrator.

 

In Illustrator scripting, there is no export option for TIFF, there is only ExportOptionPhotoshop.

 

Let me know the possibility for exporting the eps as tif.

 

regards,

Sashi

Can’t get spot "XXXX" - Applescript in Illustrator

$
0
0

I am trying to apply a swatch to a new rectangle using the script below, but for some reason I keep getting an error. I've tried changing to different swatches (some custom spots in the document, some PMS values) and all of them return the same error. Anyone have any ideas what I have missing? Using CS6.

 

 

Script:

 

             setpathReftomakenewrectangleatlayer 3 ofdocument 1 ¬

          with properties {bounds:{0, 0, |width|, -|height|}, fill color:{class:no color info}, stroke color:{class:no color info}}

 

             setThroughCuttoeverypage itemoflayer 3 ofdocument 1

 

             setstroke colorofThroughCutto {class:spot color info, tint:100, spot:spot "Through Cut"}

 

 

 

Error:

 

     error "Adobe Illustrator got an error: Can’t get spot \"Through Cut\"." number -1728 fromspot "Through Cut"

Anything similar to javascript's setInterval in ExtendScript?

$
0
0

I need a way to poll my server for new jobs for the illustrator script to work on every few hours.

I tried with $.sleep(), but that is blocking, I need a non-blocking way to do this.

Any advice?

 

Thanks!

Kashmira

Setting Object Anchor

$
0
0

Hi everybody!

 

anchor.png

 

I'm trying to access this little ui-element one here via shortcut.

Unfortunately it can't be set in keyboard-shortcut preferences.

I use it quite often, and it is a pain to hit one of these 5x5 pixel-sized squares with the mouse.


This property can be used with e.g. "rotate myRectangle angle 45 about center" via applescript,
but can it also be set like if pressed by a human in the user-interface with or without an active selection?

 

In the image you can see the result after pressing ctrl+7 (top left) for example.

bottom-right would be ctrl+3 and so on...

 

ctrl+7   ctrl+8   ctrl+9

ctrl+4   ctrl+5   ctrl+6

ctrl+1   ctrl+2   ctrl+3

 

If, at all, how can this be done? Thanks in advance.

Kai

Any great Javascript training available online?

$
0
0

Hi,

I am an artist who appreciates the awesome power of Javascript, and I have come to realize how great it would be to become proficient in it.

I wanted to ask this community:

1. Can you recommend any really excellent Javascript training for beginners?

2. Can you recommend any really excellent Javascript ILLUSTRATOR training for beginners?

 

These resources can be free or paid for, either way.

I have used Lynda.com before and video tutorials are great.  I am open to anything (Web, books, DVDs) I am even considering classes taught locally.

 

Suggestions?

 

Thanks!

Dave


Please would someone tell me how to centre justify text boxes in a window created in Javascript for Illustrator. Expect this has to be done when creating the Object(s), but I'm new to scripting and don't know the syntax.

$
0
0

function getCutterID(){

var CWindow = new Window ("dialog", "Layout ID");

var CInputGroup = CWindow.add ("group");

var CText = CInputGroup.add ("edittext", undefined, "");

CText.characters = 7;

CText.active = true;

var CButtonGroup = CWindow.add ("group");

CButtonGroup.alignment = "right"; CButtonGroup.add ("button", undefined, "OK"); CButtonGroup.add ("button", undefined, "Cancel");

CButtonGroup.active = true  

CWindow.show ();

 

return CText.text

CWindow.close ();

};

Overprint question

$
0
0

If I were to select some text, then checkmark 'Overprint Fill' in the 'Attributes' pane, is there a way to tell with JavaScript that the text was set to overprint?

 

I've been experimenting with this code in ExtendScript, but it keeps returning false:

 

var doc = app.activeDocument;

$.write(doc.textFrames[0].textPath.fillOverprint + '\n');

 

Thanks.

 

Jay

Script for Selecting Open Paths in Illustrator CS6

$
0
0

I have created this script for selecting open paths in illustrator cs6 as the graffix plugin is not working under CS6.

 

Just save the following text in /Applications/Adobe Illustrator CS6/Presets/en_US/Scripts/Select Open Paths.js

 

 

if (documents.length > 0 && activeDocument.pathItems.length > 0){
 
          var allPaths = activeDocument.pathItems;
          var allPathsCount = allPaths.length;
          var openPathsAreLocked = false;
          var lockedOpenPaths = 0;
          var locked = false;
          for (var i=0; i < allPathsCount; i++){
                    allPaths[ i ].selected = false;
 
                    if( ! allPaths[ i ].closed){
 
                              try{
                                        allPaths[ i ].selected = true;
                              } catch (e) {
                                        openPathsAreLocked = true;
                                        lockedOpenPaths++;
                              }
 
                    }
          }
          if (openPathsAreLocked) alert (lockedOpenPaths + " open paths are locked or hidden (or their layer is locked or hidden) and cannot be selected");
}

Scripts: Select an object with a note, duplicating and applying swatch

$
0
0

I am trying to write a Javascript that can do the following:

 

1) Select an object whose note has <Object Name> (so its layers is also selected)

2) Duplicate the layer of that object

3) Rename the new layer to <Layer Name>

4) Apply a swatch to the object on the new layer (the object is only single colour)

5) Apply a new note to the object (over-writing the original note).

 

I also want to write a separate script that can do the following:

1) Select an Object whose note has <Object Name> (so its layer is selected as well)

2) Hide all other layers

3) Save a copy of the document with a specific name

 

I can do this as an Illustrator action. However, I need several different copies of the scripts where the Object Name, Layer Name, Swatch and File Name changes.

Re-recording the action to change the names is cumbersome.

 

I have looked at the Illustrator scripting reference, but cannot see any commands for select objects by their notes.

 

I was wondering if someone could give me some pointers on how to proceed (Or possibly, if feeling very generous, could write the script for me )

How to rename a layer like filename (with an action)

$
0
0

Could anyone help me to rename a layer of illustrator like document file name? (with an action)

Thank you

Mauro

Viewing all 12845 articles
Browse latest View live


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