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

app.executeMenuCommand() problems

$
0
0

I'm using AI CC 2017 and it has been brought to my attention that my app.executeMenuCommand("doc-color-cmyk"); doesn't work some times when my script is ran.

 

#target illustrator

function test(){

    var doc = app.activeDocument;

    app.executeMenuCommand("doc-color-rgb");

    app.redraw();

};

test();

 

I tested the above snippet and sure enough, nothing happens.

Then, I went to the menu item and hovered over it to reveal the CMYK/RGB menu items in the document color space (without choosing one even), and it now works.

 

Is this the same thing that's happening with the Actions not registering the recorded scripts menu items?

It is not acceptable when they have to show this item, however rare it might be!

 

I went by with actions for this purpose, but having this come up was a rather unwelcome 'surprise'.


Break link to symbol

$
0
0

If I right click on a symbol instance, I get a menu item, "Break link to symbol."  How can I do that same thing in Javascript?

 

1) That is, how do I use Javascript to break the link between a SymbolItem and the Symbol it represents? (i.e. without deleting the Symbol?)

 

2) Once the link is broken, how do I locate the Layer that was created when the link was broken?  That is, once the link is broken, it is no longer a SymbolItem; it becomes a Layer instead.  How do I locate that Layer?

 

3) How do I convert the Layer to a GroupItem?

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?

Sorting Layers

$
0
0

I have a map of the US that is broken down into counties.  Each state has its own layer and the counties are sublayers.  I am currently going through and naming all of the counties, but I need to be able to alphabetize them.  Is there a way to do this?

 

Thanks

Setting Scale Corners in a script

$
0
0

I'm writing a script to fit an object into a specific sized box. I'm using:

 

artwork[0].resize(scale, scale ,1,1,1,1,scale);

 

in order to change the size. Everything seems to be working fine except if I have the "Scale Corners" check box in the Transform palette turned off. Then, of course, it doesn't scale the corners!

 

I can't figure out of there is a way to either, override that in the script or change the setting and then change it back when its done.

 

I tried:

 

getBooleanPreference("Scale Corners");

 

to see if I could get to it that way, but it doesn't match up with what is shown as selected!

 

Any ideas?

Cannot change font of ScriptUI controls

$
0
0

For example, following script:

 

var w = new Window('dialog');
var myStatic = w.add('statictext', undefined, "Hello World!");

//myStatic.graphics.font = "Arial-Bold:24";
//myStatic.graphics.font = "Verdana:16";
//myStatic.graphics.font = "Tahoma:24";


//myStatic.graphics.font = ScriptUI.newFont ("Tahoma", "Bold", 30);


//myStatic.graphics.font = ScriptUI.newFont (myStatic.graphics.font.name, "Bold", myStatic.graphics.font.size);


//myStatic.graphics.font.size = 30;

w.show();

 

All commented lines are my different behaviours to change a font of statictext, or at least its size. All them do not working in my AI CC 2015.

 

I note what whole UI in my AI have not system UI look&feel, but AI's custom, i.e. dark background, gray text and etc. Is it matter? How to workaround it?

What the heck is with the weak JPG Export options??

$
0
0

It's all in the title.. Why are there only 11 weaksauce options for jpg export!? no color model options, no output resolution options, no compression options....

 

I'm sincerely hoping this is another case of "adobe just didn't document the rest of the options"...

 

Anybody have any insight? Trying to export a document as jpg with the following settings:

 

RGB

maximum quality (10)

progressive

300ppi

Export selected items as PNG, SVG in different dimensions in AI CS6 and older

$
0
0

1) In latest Illustrator versions we have exportSelectionAsPNG method, it exports PNG with 100% scale, but what value should be passed in "options" parameters if I want export different scale?

 

2) In Illustrator CSx we haven't even exportSelectionAsPNG.

How can I export selected items (SymbolItem/PathItem/etc)?

I readen Illustrator ExtendScript reference, looken at C/C++ source code of Illustrator SDK, and even tried reverse-engineering of Illustrator DLLs, but didn't yet found any way to do this simply.

I found only 2 ways to do it tricky - via creating artboard and duplicate art, and via creating layer and duplicate art.

 

2.2) Way with artboard is preffered for me, but there is a problem. My new artboard is creating inside first of document's artboards, when I set x=0 and y=0 it uses coordinates of my first artboard, i.e. new artboard creates as a nested artboard, and nested artboard when exporting have non-transparent background, and I don't see any way to create new artboard outside 1st artboard, only set x < 0 and y > 0, but it is dirty trick, I even cannot determine what first artboard's 0,0 origin isn't document's 0,0 origin actually.

 

Thank you.


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.

Select part of point text objects matching a regex expression

$
0
0

Hello! I'm looking for a way to run through a bunch of point text objects and select part of the string in each text object based on a regex expression. I found this awesome script that can do a regex find/replace, but my end goal is not to replace, but to apply a given character style to part of the string.

 

For example, I have two point text objects:

 

first / second / third

one / two / three

 

And I want to be able to select "/ second /" and "/ two /" to be able to apply a different character style to that part of each point text object. Also, i'm not sure that you can have parts of two different point text objects selected at the same time, so the script might need to apply the active text style to the matched string parts as it passes through them.

 

Is this impossible?

 

Thanks!

find fonts in illustrator files pdf, eps, ai illustrator javascript

$
0
0

Hi Friends

 

any can help me . I need code for find fonts of the files >pdf. eps. .ai using illustrator javascript without indesign.

Sorting Layers

$
0
0

I have a map of the US that is broken down into counties.  Each state has its own layer and the counties are sublayers.  I am currently going through and naming all of the counties, but I need to be able to alphabetize them.  Is there a way to do this?

 

Thanks

Export selected items as PNG, SVG in different dimensions in AI CS6 and older

$
0
0

1) In latest Illustrator versions we have exportSelectionAsPNG method, it exports PNG with 100% scale, but what value should be passed in "options" parameters if I want export different scale?

 

2) In Illustrator CSx we haven't even exportSelectionAsPNG.

How can I export selected items (SymbolItem/PathItem/etc)?

I readen Illustrator ExtendScript reference, looken at C/C++ source code of Illustrator SDK, and even tried reverse-engineering of Illustrator DLLs, but didn't yet found any way to do this simply.

I found only 2 ways to do it tricky - via creating artboard and duplicate art, and via creating layer and duplicate art.

 

2.2) Way with artboard is preffered for me, but there is a problem. My new artboard is creating inside first of document's artboards, when I set x=0 and y=0 it uses coordinates of my first artboard, i.e. new artboard creates as a nested artboard, and nested artboard when exporting have non-transparent background, and I don't see any way to create new artboard outside 1st artboard, only set x < 0 and y > 0, but it is dirty trick, I even cannot determine what first artboard's 0,0 origin isn't document's 0,0 origin actually.

 

Thank you.

Reworking Photoshop layer renaming script for Illustrator

$
0
0

The Photoshop scripting guru Paul R over at RetouchPro has created a really cool script to batch rename and number selected Photoshop layers. I haven't found anything similar on the Illustrator side.

 

He's given permission for me to post it here in my hopes that some Illustrator scripting genius could come up with a similar script for Illustrator. Would it be terribly difficult to convert this into something Illustrator could use?

 

http://www.mediafire.com/file/g7usr73u0236p0a/Rename_&_Renumber_Selected_Layers.jsx

 

http://www.mediafire.com/file/dbah74x13bsa74c/Rename_&_Renumber_Selected_Layers.jsx.zip

 

rename-layers.png

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");
}

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

How to add multiple strokes with offset path?

$
0
0

Hello,

 

I would like to create a script that can create multiple strokes with offset path ( incremental or decremental (user will enter value) )

Is it possible to add multiple strokes? I could not find any example in scripting reference or elsewhere.

Note: Blending does not give exactly the same results because sometimes especially when you're dealing with font outline paths it is being blended in wrong a way.

I'd be glad if someone give at least the main command in for loop.  I would try to do rest and will be sharing here as I find the solution.

Thanks,

Best Regards.

 

question.jpg

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 to add in item to menu of Illustrator to activate script instead of File - Scripts menu?

$
0
0

I wrote a script and installed it to Presets, but in real work I find in veeeeery inconvenient to activate script with File > Scripts.

I don't need my own panel or toolbar, just menu item for File (or another) menu, or some else more convenient than File > Scripts.

I was seen in web some like "app.menus", but for InDesign, and there are no same in docs of Illustrator.

How to solve my problem?

ps

Illustrator CC2015, but I wish make my script compatible with CS6 or even lower.

get alert msg

$
0
0

is it possible to get msg displayed in font missing alert

using adobe illustrator script

Viewing all 12845 articles
Browse latest View live


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