I'm modifying a javascript that makes an export of each layer contained in an Illustrator document and I want to specify the method used for anti-aliasing (either Type Optimized or Art Optimized). Similarly to the option under the "Image size" tab in the "Save for the Web" panel.
I didn't find any antiAliasingMethod property in the ExportOptionsPNG24 properties (only an antiAliasing property that accepts boolean). So I wonder if it is actually possible to do it through scripting?
Just in case any body would like to have the ability to import .csv and tab-delimited .txt files into Adobe Illustrator as datasets, (similar to Indesign's Data Merger), here is a tool which will help you out. Using the VariableImporter, it is now possible to import those formats, designate header columns (which will be variable names in Illustrator), and to specify Text/Visibility/Link variable types for each variable.
To assign visibilitydesignation to a variable, you can use the # ('pound') symbol in front of the column name.
To assign linked file designation to a variable, you can use the @ ('at') symbol in front of the name.
The names have to follow XML tag naming standard:
Names can contain letters, numbers, and other characters
Names cannot start with a number or punctuation character
Names cannot start with the letters xml (or XML, or Xml, etc)
To run, go to above link, and click on the "Raw" button, download by using browser's context menu and choose "Save As" with a .jsx extension. It will run when double-clicked, and also by choosing File > Other Script inside Illustrator.
I wish to print in a PDF to use the automatic rotation so that the artboards are printed in one direction (portrait). The PDFs are needed for a RIP.
I figured out the possibility to export (save) as PDF but the solution for the automatic rotation is pretty complicated, so I hope this one is easier.
(Putting a rectangle on top of all at the size of the artboard, group the colliding elements, rotate the group if it's landscape with the center of the rectagle and let the artboard fit to the rectangle afterwands and that's for all artboards, see what I mean?)
Here's the point and the script I am working on. I get a failure-response about embedding fonts but I do not know what's missing as the .ps solution at the bottom works. What is needed is a PDF-X3 with flattened Transparency, Coated FOGRA 39, Spot Colors to 4C
/* var originalInteractionLevel = userInteractionLevel;
userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; */
var ordner = 'C://_temp//'; //The PDF sould be written to a absolute Path in the Network of a Windows environment
var dateiNameExt = app.activeDocument.name.split( "." ); //Getting the name of the active Document
var dateiName = dateiNameExt[dateiNameExt.length-2]; //Extract .ai
var druckOptionen = new PrintOptions();
druckOptionen.printPreset = "Netzfeld-test"; //My Print Preset
druckOptionen.PPDName = "Adobe PDF";
druckOptionen.printerName = "Adobe PDF";
var druckJobOptionen = new PrintJobOptions();
druckJobOptionen.name = dateiName;
var dateiPfad = new File (ordner + dateiName + ".pdf"); //Use the document name and the path to save the pdf
druckJobOptionen.file = dateiPfad;
druckOptionen.jobOptions = druckJobOptionen;
//Sone useless stuff I suppose
var fontOpts = new PrintFontOptions();
druckOptionen.fontOptions = fontOpts;
//Set some font options
fontOpts.downloadFonts = PrintFontDownloadMode.DOWNLOADCOMPLETE;
fontOpts.fontSubstitution = FontSubstitutionPolicy.SUBSTITUTETINT;
// Print with options
app.activeDocument.print(druckOptionen);
/* userInteractionLevel = originalInteractionLevel; */
/* fit_frame_to_text.js -- resize selected text frames to fit their current text content [Adobe Illustrator]
This script is released into the public domain. No warranty provided, E&OE, caveat emptor, etc.
Notes:
- Text frame must be rectangular area text, vertically aligned to avoid skewing when its path height changes.
- On success, fitFrame returns new height in points. If text frame is empty it is resized to 0 height.
- If text frame was point- or path-based, or not a text frame, fitFrame returns -1 to indicate it was ignored.
Caution:
- JSX scripts should use anonymous functions and local vars only whenever possible, as AI's shared JS interpreter gets increasingly fragile as globals are defined, eventually resulting in JS (and AS!) commands repeatedly failing with PARM ('MRAP') errors until AI is relaunched. (Though even this doesn't necessarily avoid problem; e.g. repeatedly running any JS script from AS seems to blow up after a while, after which AS commands randomly fail as well.) */
(function() {
function fitFrame(textFrame) { // textFrame must be a TextFrameItem if (!(textFrame instanceof TextFrame && textFrame.kind == TextType.AREATEXT)) { // ignore point/path text return -1; } var limit = 0.2; var textPath = textFrame.textPath; var textLength = textFrame.contents.replace(/\s+$/, "").length; // get length of printable text (ignores trailing whitespace) if (textLength === 0) { textPath.height = 0; // text frame is empty so set to zero-height and return return 0; } var h = textPath.height; // if frame has no height, add some to get things started if (h < limit) { h = limit; textPath.height = h; } // overflow checker; this checks length of printable text to index of last visible character in frame var hasOverflow = function() { var lastLine = textFrame.lines[textFrame.lines.length-1]; if (lastLine === undefined) { // no lines are visible (frame is too small) return textLength > 0; } return textLength > (lastLine.characters[0].characterOffset + lastLine.length - 1); } // adjust text frame height using two-stage divide and conquer; crude, but works, and acceptably fast // find initial approximate min and max heights between which text overflow occurs var oh; if (hasOverflow()) { do { oh = h; h *= 1.5; textPath.height = h; } while (hasOverflow()); } else { do { oh = h; h /= 1.5; textPath.height = h; } while (!hasOverflow()); } // narrow the difference between min and max approximations till it falls within limit var d = oh - h; if (d < 0) { d = -d; } while (d > limit) { d /= 2; h += (hasOverflow() ? d : -d); textPath.height = h; } // if final reduction caused overflow, undo it if (hasOverflow()) { textPath.height = h + d; } return textPath.height; }
for (var i = 0; i < activeDocument.selection.length; i++) { // iterate over each item in AI's janky selection object fitFrame(activeDocument.selection[i]); } })();
I have been tying to figure out how I could easily embed multiple linked images easily. I have some 1000 .svg images which have about 1-7 .tif images linked in to them. I now need to get those links embedded and becouse of the amount of images I'm hoping to make an action out of it. I have a script to embed single image in .svg but haven't have luck with multiple embeddings.
There is a way to reach the command "Make/Release Clipping Mask" in the Layer window via script?
What I'm trying to achieve is to create a rectangle using the size of my artboard, name it "CLIP", put it on the top of my active Layer and set it as my mask.
I would like to "place" a .dxf file into my document via a script but no luck so far . With the script below, as a test, I can place a .tiff file with no issues but not a dxf. I can Open the .dxf file but I need to Place due to a custom template. I also can manually place the .dxf via the AI menus but again need to automate. The script blow gives an AI Unknown Error when I try to run with a .dxf. (FYI - using For/Next as I plan to Loop through a folder but now just testing with one file).
Set App = CreateObject("Illustrator.Application")
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim CustomTemplate : CustomTemplate = "S:\SOCAL\Section_32\_Control Data\SWS_template.ait"
Set SourceFolder = FSO.GetFolder("S:\SOCAL\Section_32\Road DXFs")
I suspect it has to do with some custom AutoCad formatting/code needed but what I found in the AI samples did not make a difference. I also thought of using the statement:
App.ExecuteMenuCommand("AI Place")
Which does work but I still have to select the .dxf file manually. Maybe there is a way to have my code select the file???
If someone would care to try to place one I would greatly appreciate it. Though I code mostly in VBscript I would be more than happy to take a JavaScript.
Although I'm new to scripting Illustrator, I'm looking for a script that can help me – and merge 10 SVG-files into one layered AI-file.
I get a lot of projects which contents 10 individual SVG-files that are exported from a GIS program (Map data). Each SVG-file contents specific stuff like water, roads, houses etc., so when 'merging' them together, the result will be one final map. I'll need to copy each SVG-file into a new layer so the end result will be a layered AI-file.
I was thinking that the script should do something like this:
- Find a folder using a dialog box and open its SVG-files (each project has 10 SVG-files (same size))
- Copy the content from each SVG-file into a new document (same size as the SVG-file) on a separate layer
(The new document will then have 10 layers)
(Naming each layer the same as the SVG-file name)
- Close all the SVG-files, leaving the new AI-file on the screen
I'll would be very glad if someone could point me in the right direction for this project … Thanks
A couple of years ago I had some awesome help making a couple of scripts to rename layers based on the containing artboard (Re: Script to Rename Artboards with Layer Names). One problem posed (and solved) was:
- Each artboard has a name.
- Each layer NEEDS a name.
- There are an equal number of layers and artboards.
- Only one layer "exists" on each artboard. (i.e. They share coordinates.)
- I would like to name the layer with the same name as its encompassing artboard.
The solution was:
function artboardLayerNameMatch() { if (app.documents.length == 0) { alert("No Open / Active Document Found"); } else { var doc, i, l, ab, sel, n; doc = app.activeDocument; for (i = 0, l = doc.artboards.length; i < l; i++) { ab = doc.artboards[i]; doc.artboards.setActiveArtboardIndex(i); doc.selectObjectsOnActiveArtboard(); sel = doc.selection[0]; sel.parent.name = ab.name; doc.selection = false; } }
}
artboardLayerNameMatch();
Now, I'm wondering if the reverse is also possible?
The new scenario is:
Each layer has a name.
Each artboard NEEDS a name.
There are an equal number of layers and artboards.
Only one layer "exists" on each artboard. (i.e. They share coordinates.)
I would like to name the artboard with the same name as the layer that resides “on” it
The CS6 JavaScript scripting interface allows for limited scripting for plug-ins. A plug-in can define a command, with an event and notifier, and a handler that performs some action. A JavaScript script can then use the app.sendScriptMessage() method to send parameters to that plug-in-defined command, and receive a plug-in-defined response.
For example, the Adobe Custom Workspace plug-in defines a command "Switch Workspace". A script can invoke this command with the following code:
result = app.sendScriptMessage("Adobe Custom Workspace" , "Switch Workspace", '<workspace="Essentials" >');
In this case, the value that the plug-in returns is the string "<error=errNo>".
Does anybody know where or how I can find out the native plug-in commands and what parameters they accept?
Hi, I have a file containing images [BROWN], text[RED] and some pathitems frames[YELLOW and GREY]. I've seen that all the stuff is aligned by the center of each image like shown in the picture.
The image will later be cropped by the yellow frame, I'm looking for a method to move the text closer to the bottom of the yellow frame. In a perfect world text should also rotate following the yellow frame bottom path to avoid being cropped.
I'm pretty sure it can be done easily in a couple of lines if it were a rectangle because there is a rectangle method. Instead here is an apparent parallelogram composed by 200 anchor points (imported from another software).
YELLOW : hundred points pathItems
RED : textFrames
BROWN : rectangular image that has a square center. A bitmap image
GREY : pathItems rectangles that I plan to use for control of textFrame position
I'm very new to Ai JS scripting so I don't know (yet) every items of all the 300 hundred pages of the JS DOM. I'm lacking ideas for methods (either JS or ESTK).
I can select any object, move item, do any aiAction, do any actionmenu, calculate half the height of a rectangle... but what I need is a snippet to find that vertical offset to be sure to keep text inside the yellow frame... This is basic geometry and topology, my brain can perfectly use a mouse to do it at least.
My idea is to draw a line from the image center and intercept a line (or spline) of the yellow frame; then calculating the tangent angle for the text. Otherwise define parallelogram by using a (u;v) vector reference like in a good old maths problem!
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.
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.
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.
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.
I'm working on an illustrator extendscript where I have to get number of artboards for each opened document. The code may look like this
for ( var i=0 ; i<app.documents.length ; i++ ) {
alert(app.documents[i].artboards.length);
}
But each time I run this script, it returns the number of artboards for active document (only) each time.
for example if I've 3 documents opened ie. doc1 , doc2 , doc3
the number of artboards in doc1 is 1, doc2 is 4, and in doc3 is 2
and I'm currently working with doc2 ( doc2 is active)
then the script alerts 3 times saying: 4, 4 and 4 each time.
please help me
Also tell me if this code is correct or not
thanks in advance
update: I also tried alert( app.documents[1].artboards.length ); , It doesn't work either. having the same problem with this too (shows no: of artboards for active doc)
What I need is to export as PNG my groups this way: “group_name_index_R_G_B.png”. RGB value(color) of each <Path>.
Example for group name ground_9:
ground_9_1_89_86_142.png
ground_9_2_144_85_130.png
…
ground_9_13_215_185_65.png
Most important for me is RGB value color of each <Path>. Also, each <Path> should be same size and with transparency, size of it should be as artboard size where path located. So all png files should be the same size and with 1 triangle inside.
I don't know if with scripts possble to do all this, I would like to listen any advices about that.