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

Creating a dynamic action to use with app.doScript() method.

$
0
0

Since building dynamic actions is a topic unto itself, we often search for a reference thread to show somebody how to do this - and we often do so while trying to discuss work which is already involved and has nothing to do with actions or loading and playing them. Therefore I'm creating this thread to show an example and I'll paste the url to it when such questions arise.

 

Sometimes in Illustrator scripting we need to accomplish tasks which (sometimes counterintuitively) do not have scripting access via the DOM.

Fortunately since Illustrator CS6, they gave us the ability to play an action from a script with the app.doScript() command - which is not at all the same as Indesign's function of the same name. This one lets you play an action that exists inside the Actions panel. Immediately this may seem disappointing as users cannot be counted on to have specific actions at any given time.

However, they also gave the ability to load and remove actions from .aia action files. Your .aia file just needs to be somewhere and app.loadAction() can read it right into the Actions panel. Same with app.unloadAction(setName, actionName) - where (thanks to qwertyfly) using (setName, "") an empty string argument for the action name will remove the entire set. And when you try to remove an action that does not exist, well, it throws an error - which is how you can check for making absolutely sure that an action set is completely removed.

This may seem like a lot of work - to write a file, read it, play it and then discard it, often to do something that you'd think scripting should do in the first place.

 

Sometimes the action alone is enough to satisfy an objective - such as changing the document color mode. Other times it is necessary to alter actions in order to get use out of them - such as when you try to create a routine for saving a high-resolution "Export" JPG that is different in output and options form the "Save for Web" JPG. You may want to change some of the parameters such as resolution or the actual destination of the file.

Here is how you can do this.

 

First, record your action as you would normally: record a new set with a new action, call them what you need and then in the Actions flyout menu, save out a .aia file where you can find it. You can open the file in a text editor and read the contents - they are lines of special Actions 'code' which contains some cryptic text.

There are lines which look like a bunch of gibberish characters, they are hex-encoded strings for some parameter item which are strings, and they contain above them a number to signify the amount of characters inside the encoded string. (this is important later because this number also needs to be set properly when you put your own value in there) Other parameter items are simple numbers, but their keys are still obscured.

The truth is, while the string parameters are hexadecimal-encoded, the keys are both hexadecimal and decimal encoded! So if you wanted to know the special 4-letter keys, you'll have to run those through two decoder routines.

 

Next, you will need to put this entire string into your script and use some string-replacement or string-building to put your own data in those places of the action string where they matter. For example, putting your own file path into a save action.

 

And, after that you need to write a procedure for writing this new altered string to the file system and loading it into your Actions panel. Mind you, to leave things "as they were" you would need to remove the .aia file and the action that you have loaded.

 

Let's try with the save-a-jpeg workaround!

Here is the .aia string which is recorded from an Export JPEG action.

 

Screen Shot 2017-02-10 at 3.04.33 PM.png

/version 3

/name [ 8

  5475746f7269616c

]

/isOpen 1

/actionCount 1

/action-1 {

  /name [ 11

  4578706f7274204a504547

  ]

  /keyIndex 0

  /colorIndex 0

  /isOpen 1

  /eventCount 1

  /event-1 {

  /useRulersIn1stQuadrant 0

  /internalName (adobe_exportDocument)

  /localizedName [ 9

  4578706f7274204173

  ]

  /isOpen 1

  /isOn 1

  /hasDialog 1

  /showDialog 0

  /parameterCount 7

  /parameter-1 {

  /key 1885434477

  /showInPalette 0

  /type (raw)

  /value < 100

  0a00000001000000030000000200000000002c01020000000000000001000000

  69006d006100670065006d006100700000006f00630000000000000000000000

  0000000000000000000000000000000000000000000000000000000000000000

  00000100

  >

  /size 100

  }

  /parameter-2 {

  /key 1851878757

  /showInPalette 4294967295

  /type (ustring)

  /value [ 25

  2f55736572732f566173696c7948616c6c2f4465736b746f70

  ]

  }

  /parameter-3 {

  /key 1718775156

  /showInPalette 4294967295

  /type (ustring)

  /value [ 16

  4a5045472066696c6520666f726d6174

  ]

  }

  /parameter-4 {

  /key 1702392942

  /showInPalette 4294967295

  /type (ustring)

  /value [ 12

  6a70672c6a70652c6a706567

  ]

  }

  /parameter-5 {

  /key 1936548194

  /showInPalette 4294967295

  /type (boolean)

  /value 1

  }

  /parameter-6 {

  /key 1935764588

  /showInPalette 4294967295

  /type (boolean)

  /value 1

  }

  /parameter-7 {

  /key 1936875886

  /showInPalette 4294967295

  /type (ustring)

  /value [ 1

  32

  ]

  }

  }

}

 

We can see many parameters and their various cryptic blocks, but what you want to do is decode as many /type (ustring) elements as possible to get a sense of what the action is doing. At this website, you can do this fairly easily although tediously: Convert Hexadecimal To String Online

For example: "4a5045472066696c6520666f726d6174" turns into "JPEG file format".

In this action example, I am not worried about changing the other parameters dynamically - I'm assuming the settings used in my action are suitable for my purposes such as resolution being 300 for all time. The part I'd like to change is my file path so that my JPEG goes to the right place.

/value [ 25
2f55736572732f566173696c7948616c6c2f4465736b746f70
]

This line yields: "/Users/VasilyHall/Desktop"

So this is the line I'll need to replace.

 

Before anything else - here is how I'd embed the action string with ease. Using a text editor like Sublime text which lets you put many cursors down at one time, I can paste the action string in and find every nextline character. Then it's easy to highlight each line and put quotes around it as well as a comma in the end, or plusses - depending if you want to store the string as an array or a plain string in the script.

Screen Shot 2017-02-10 at 3.16.48 PM.png

I find the plusses a little cluttering so I opt to use this format:
var actionString = [     "string",

     "string"

].join("\n");

 

So my dynamic portion of the string which will be used with string replacement would look like this:

 

"  /value [ {{number_of_characters}}",

"  {{hex_encoded_path}}",

"  ]",

 

When the action is ready to be dispatched, a string replacement would look like this:

var myNewPath = Folder.myDocuments.toString() + "/Destination";

var myNewPathEncoded = hexEncode(myNewPath); // find a hex encode function via google
var thisActionString = actionString.replace("{{hex_encoded_path}}", myNewPathEncoded).replace("{{number_of_characters}}", myNewPath.length);

 

Now it's time to write the file.

var f = File(actionFileLocation);

f.open('w');

f.write(thisActionString);

f.close();

 

And now it's time to load the action.

app.loadAction(actionFileLocation);

 

Now we can play the action.

app.doScript("Export JPEG", "Tutorial");

 

This should save your jpeg, and as of this writing, this is the only way to get the JPEG export which isn't the Save-for-Web variety.

But, let us not forget the cleanup.

 

Remove the .aia file:

f.remove();

 

Remove the single-use dynamic action:

app.unloadAction("Tutorial", "");

 

There you have it: building dynamic actions to do simple and non-simple things, which regular scripting just can't do.


How to script the 'Export as...' feature?

$
0
0

I want to export artboards as PNG files in a JavaScript. In the past I used the ExportOptionsPNG24, but font comes out fussy in small sizes.

Is there a way to script the export-as-feature in Illustrator? (File > Export as > PNG with artboards and anti-aliasing/Type optimized)

I haven’t found anything in the scripting reference 2017:

http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/illustrator/sdk/CC2017/Illustrator_ JavaScript_Scripting_Reference.pdf (edited)

Any hints welcome. I just want to know, if it's possible. No need for a final script. ;-)

 

Printing in a PDF with Filename - Folder and Filename are ignored

$
0
0

With a script for Illustrator I try to make the printing-process for our staff easier. They need to specify different Folders for A4 and A3 PDFs.

 

First thoughts: I have Illustrator-Files with different Artboard-sizes and Page Orientations. Our RIP does not recognize the document-pages being A4 or A3. So I have to split the File in at least two PDFs, one is A4, one is A3. All of them must be in Portrait-Mode so that A4 and A3 is used completely. Printing in a PDF (Windows workflow) works with PrintOrientation set to AUTOROTATE.

Rotating the artboards with all Objects and save as PDF would be great but I figured out it's pretty complicated. So I would like to go on with printing in a PDF and using the Autorotate feature.

 

Where I am stuck: The filename and the printJobOptions seem to be ignored. I need to specify the path of the filename and the Media-Size but the PDF-Settings of the virtual PDF-Printer I am using as standard seem to be used first and all the properties in the Script are overwritten. This is the Standard-Setting of the PDF:

AdobePDF.png

This is the script so far:

#target Illustrator
#targetengine main

/*
var originalInteractionLevel = userInteractionLevel;
userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
*/

var docRef = app.activeDocument;
var options = new PrintOptions();

/* printJobOptions.printPreset = 'Netzfeld-test'; */

// Printer
options.printerName = 'Adobe PDF';
options.PPDName = 'Adobe PDF';

// Fonts
var fontOpts = new PrintFontOptions();
fontOpts.downloadFonts = PrintFontDownloadMode.DOWNLOADCOMPLETE;
fontOpts.fontSubstitution = FontSubstitutionPolicy.SUBSTITUTETINT;
options.fontOptions = fontOpts;

// Color
var colorOptions = new PrintColorManagementOptions();
colorOptions.intent = PrintColorIntent.RELATIVECOLORIMETRIC;
colorOptions.colorProfileMode = PrintColorProfile.CUSTOMPROFILE;
colorOptions.name = "Coated FOGRA39 (ISO 12647-2:2004)";
options.colorManagementOptions = colorOptions;

// Seperation
var sepOptions = new PrintColorSeparationOptions();
sepOptions.convertSpotColors = true;
sepOptions.overPrintBlack = true;
sepOptions.colorSeparationMode = PrintColorSeparationMode.COMPOSITE;
sepOptions.colorProfileMode = PrintColorProfile.SOURCEPROFILE;
options.colorSeparationOptions = sepOptions;

// Print Coordinates
var coordinateOptions = new PrintCoordinateOptions();
coordinateOptions.emulsion = false; // reverse from right to left
coordinateOptions.fitToPage = false; // fit artwork to page size
coordinateOptions.position = PrintPosition.TRANSLATECENTER;
coordinateOptions.orientation = PrintOrientation.AUTOROTATE;
options.coordinateOptions = coordinateOptions;

// Filename and Artboards are ignored
var printJobOptions = new PrintJobOptions();
options.printJobOptions = printJobOptions;

// Filename
var docPath = new File('C://_temp//bla.pdf');
printJobOptions.file = docPath;

// Artboards
printJobOptions.designation = PrintArtworkDesignation.VISIBLEPRINTABLELAYERS;
printJobOptions.printArea = PrintingBounds.ARTBOARDBOUNDS;
printJobOptions.collate = true;
printJobOptions.printAllArtboards = false;
printJobOptions.artboardRange = '1';

// Print
docRef.print(options);
/*
userInteractionLevel = originalInteractionLevel;
*/

What's wrong with it? What's missing?
The example in the Scripting Manual of Illustrator on page 176 doesn't seem to work either when I print to PDF: http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/illustrator/sdk/CC2017/Illustrator_ JavaScript_Scripting_Reference.pdf

batch find & replace text in Illustrator files in a folder?

$
0
0

I found this script which work greats on any currently open Illustrator files, but I would like it to be able to run the action on a Mac OS folder, open the first Illustrator, runs this javascript, save & close that file, then loop through all other Illustrator files in a folder and repeat the process, until the last file.

 

  1. function FindAndReplaceScript_AllOpenDocuments(){     
  2.     for(var i=app.documents.length -1; i > -1;  i--){     
  3.         app.documents[i].activate(); 
  4.         var aDoc = app.documents[i]; 
  5.              
  6.         var searchString = /VT/gi;    
  7.         var replaceString = ‘VHB';      
  8.              
  9.         var theTF = aDoc.textFrames;     
  10.         if (theTF.length > 0) {     
  11.             for (var j = 0 ; j <theTF.length; j++) {     
  12.                 var aTF = theTF[j];     
  13.                 var newString = aTF.contents.replace(searchString, replaceString);     
  14.                 if (newString != aTF.contents) {     
  15.                     theTF[j].contents = newString;     
  16.                 }     
  17.             }     
  18.         } 
  19.     } 
  20. };     
  21. FindAndReplaceScript_AllOpenDocuments(); 

Newbie at Illustrator scripting needs help assigning image

$
0
0

I am trying to copy a graphic stored in a vb.net picturebox.image into an activeLayer of an illustrator document. Can anyone supply me with code as to how to do it. Also is there a way to lookup a swatch by name and not have to rely on knowing it's index as in this line of code : pathRef.StrokeColor = docRef.Swatches(3).Color. I know the swatch's name is "CutContour" I would like to assign it by name. And lastly does anybody know any good books, links, etc.. that show you how to do this kind of stuff.

 

Thanks,

Bruce

 

------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------

Imports IDAutomation.Windows.Forms.LinearBarCode
Imports Illustrator

 

Public Class FormMain
    Dim barcode As IDAutomation.Windows.Forms.LinearBarCode.Barcode = New Barcode()
    Dim illustrator As Illustrator.Application = CreateObject("Illustrator.Application")
    Dim filePath As String = My.Application.Info.DirectoryPath

 

    Private Sub FormMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        barcode.SymbologyID = barcode.Symbologies.Code39Ext
        barcode.BarHeightCM = 1
        barcode.XDimensionCM = 0.03
        barcode.NarrowToWideRatio = 2
        barcode.LeftMarginCM = 0.201
        barcode.TopMarginCM = 0.201
        barcode.TextMarginCM = 0.051
        barcode.ShowText = False
        barcode.CaptionBottomAlignment = StringAlignment.Center
        barcode.CaptionBottomSpace = 0.03

 

        Dim barcodeText As String = "CODE39UPC" 'hard code barcode content for this test

 

        barcode.DataToEncode = "*" + barcodeText + "*"
        barcode.CaptionBelow = barcodeText
        PictureBox1.Image = barcode.BMPPicture 'Display Barcode
        barcode.SaveImageAs(".\upc.png", System.Drawing.Imaging.ImageFormat.Png)

 

 

        Dim fileName As String = filePath + "\Roland VersaWorks.eps"

 

        Try
             illustrator.Open(fileName)
         Catch err As Exception
             MsgBox("Missing File: " + fileName)
             illustrator.Quit()
             Me.Close()
         End Try

 

        Dim docRef As Illustrator.Document = illustrator.ActiveDocument
        Dim pathRef As Illustrator.PathItem = docRef.ActiveLayer.PathItems.Rectangle(100, 0, 300, 100)
        pathRef.StrokeColor = docRef.Swatches(3).Color 'Set strokeColor to CutContour Swatch
        pathRef.Filled = False ' Don't Fill rectangle with anything
        docRef.ActiveLayer = docRef.Layers(2) 'Activate UPC Layer

 

        '############## I need to copy PictureBox1.image into this activeLayer! How do I do it? ###########

 


        Dim epsOptions As Illustrator.EPSSaveOptions = CreateObject("Illustrator.EPSSaveOptions")
        epsOptions.CMYKPostScript = True
        docRef.SaveAs(filePath + "\test.eps", epsOptions)
        illustrator.Quit()
        Me.Close()
    End Sub

 

End Class

Retrieve whats in the clipboard possible?

$
0
0

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

If so how?

How to sort objects alphabetically (inside of a layer)?

$
0
0

How to sort objects alphabetically (inside of a layer) on layer list?

I have already tried scripts for Layer sorting. They work indeed for the layers, but not the objects themselves packed inside.

“Fit All in Window” using JavaScript

$
0
0

I've recently started scripting in Illustrator and having a little problem. When creating a document through File tab, (File->New, Print, Letter) the created document is positioned at (0,0) and the view is focused on the document.

 

But if I create a document using JS, for example app.documents.add();, the created document isn't positioned at (0,0), but at (0,-792). I reposition the artboard and move it to (0,0) with app.activeDocument.artboards[0].artboardRect = [0, 0, 612, -792];. This moves the artboard below, out of the focused view. I need to scroll down to get the artboard into view.

 

Is there a way to focus the view on the artboard using JS? Maybe call the "Fit All in Window" command?

 

Using Adobe Illustrator CS6 64-bit on Windows 8.1 Pro


Script: rename layers?

$
0
0

Hi, is there a quick way how to renumber or batch rename all layers in a file so they would be named in consequent numbers? Doesn't have to start from exact number, I was wondering if maybe there is some sort of script that would help me with that? Thanks Pavel

Generating preview for all pageItems, layers, groups, etc. for a rebuild of the Layers panel

$
0
0

Hey guys, I can finally post on the forum again after a server issue prevented me from logging in. I recently made a near-complete and open source rebuild of the Layers panel with added features like key navigation, easier renaming, and more:

 

WaryUnpleasantAnchovy-size_restricted.gif

I plan on rebuilding this with nodeJS to handle certain behavior like the click-dragging and rearranging of layers, but one part I'm still unsure of is how to generate the live preview of any given pageItem, layer, group, or etc. Initially I thought app.activeDocument.imageCapture() could be an easy solution to this:

 

function testPreview(item, pin) {     let result = app.activeDocument.imageCapture(new File(`${extRoot}/preview/${pin}.png`), item.visibleBounds);
}

 

I assign a unique hexadecimal pin to each layer/pageItem/object, then save that as a raster image to use as the background CSS of my preview box. This does technically work but it doesn't isolate the items and prevent capturing other art above or below if in the same visibleBounds (so I'd need to toggle isolation or transparency as I recurse) and the quality is very pixelated, so I feel there must be a better way. Despite Silly-V telling me this isn't going to be viable without C++, I'd still like to try since I have no experience with C++ and it seems absurdly hard to penetrate or get started with.

 

I plan on rebuilding this so I'm mainly interested in suggestions or brainstorming if there's no workable examples to be had, but I'm curious if any one knows whether the vanilla previews in the original Layers panel are being stored anywhere on the OS like a temp folder which I might be able to access -- that'd save me from needing to slow down my panel and create them myself.

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

Applescript: Removing Groups and Layers

$
0
0

This should be a simple task, but I still haven't figured out how to do it.

 

I have a set of page items, and the are contained in groups inside of layers inside of layer inside of layers.

How can I remove the layers easily?

I looked at the reference guide, and attached the screenshot where it explains how to use the "delete" command to remove containers of objects.

But I still dont' understand how to order the command correctly:

delete page item of layer?

delete layer of page item?

delete page item of layer of page item?

None of these work.

For now, I've just used an action, but it would be helpful if I could do it within a script.

 

Any help is appreciated.

Thanks,

 

Ben

Screen shot 2009-12-21 at 10.08.25 PM.png

Simple InDesign script -> Illustrator help

$
0
0

I have this script by Peter Kahrel that reverese the order of letters in InDesign.

 

I need an Illustrator version of it. Can anybody help?

 

---------------------

//ReverseText.jsx

//An InDesign Javascript that reverses the order of any selected text.

//If no text is selected with the Type tool, nothing happens.

//Written by Peter Kahrel for InDesignSecrets.com

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

 

#target indesign

if ( "TextWordLineParagraph".search ( app.selection[0].constructor.name ) < 0 )

    exit();

s = app.selection[0].contents;

s = s.split("").reverse().join("");

app.selection[0].contents = s;

-------------------

 

Mainly using this for Arabic text in CS 3 and 4 for clients that don't have new versions - and will never buy it apparently.

 

Works great in InDesign. I've been putting the text in ID and then copying it into Illustrator. But it would be nice to skip that step if possible.

 

Thanks in advance.

Script for closing the open paths on Illustrator CC2015

$
0
0

Can someone give me a script to close all the open paths on Illustrator CC2015 ?  Thanks.

How to link with any function to any Script UI (user interface) using javascript

$
0
0

How to link with any function to any Script UI (user interface) using javascript


Script Adding text to Multiple layers and add property in Attributes Panel

$
0
0

What I'd like to do is create a JavaScript to add text to multiple layers, give the text no stroke and no fill, and enter text into the Attributes Panel.

As you can see in my screen shot, I have the same text selected in 9 of the 13 layers, which is basically pasted in the same spot on all 9 layers. The text has an Attribute of INDEX. And of course the stroke and fill don't have any color.

This text is in a template we use, but older templates don't have it. Plus the INDEX text in the Attributes Panel is used when we run an Action. It turns on and off layers and does other functions according to this attribute. So, when we open old artwork for revisions, running the script would be much quicker than opening a template, copy and pasting the text.

I have created a script to add the text. I can get it to specific layers, but cannot get the no stroke and no fill to work, and have no idea how or if it's possible to enter text in the Attribute Panel. I can upload a sample script to show what I already have, but if the Attributes Panel text won't work, then I'll just leave it as is.

Is it possible to script no fill and no stroke and the property in Attributes Panel? Is it possible in Visual Basic, though I've never programmed that before? I've gone through the JavaScript Tools Guide and couldn't find anything.

Thanks in advance everyone.

 

Windows 10

Illustrator CC 17 (64-bit)

 

Selecting a Single Anchor Point at the Start of a Script

$
0
0

Sorry to ask but is there a way to automatically select an Anchor Point?  It will always be the Lowest point (and because there will be multiple on that Y-axis) I want the Left most point.

 

Capture3.PNG

 

 

Thank you!

Importing Color to Swatch Library from Text File

$
0
0

Hi,

I have a large list of custom colors in Excel that has the color name and CMYK breakdown of each color. I'm looking for a way to import this information to create a custom Color Swatch Library. That will have the name of the color and the CMYK breakdown. So that I can easily use in Illustrator and Photoshop. Is there any way or application in doing this with out manually entering the information and creating a new library?

 

Thanks!

Why does selectedPathPoints property have more points than I've selected?

$
0
0

I selected only one point in whole document:

sss.jpg

Then ran this code:

objs = app.selection;
points = objs[0].selectedPathPoints;
alert(points.length);

 

And got this:

ddsss.jpg

Why?

How to add text in .ai file and set position, font, size and colour

$
0
0

I want to place multiple lines of of text (individually) into .ai file and set size, font, colour and position for each.

Preferably text should have origin in a single point (rather than be framed)

 

Hope anyone can help me out.

 

Thank you in advance.

Viewing all 12845 articles
Browse latest View live


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