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?
script to align selected objects to artboard
Urgent Help Scripting
I am a beginner at scripting, coding, and web design. I have been having questions regarding developing an Adobe Script that will Automatically open a PDF file I have (created in Illustrator CC 2015), Automatically change the name of two swatches to new names I have, then automatically Save with same file name plus "_Z.PDF" at the end and close the file.
Below is the code i developed with help from experts. It is designed for a Mac computer and is opened using ESTK. When I try activating, it says there is still an error in the part : var doc = app.open(f); What should I do about this? I have it underlined below too in bold italics.
function test()
{
// 1)
var thePath = "~/Desktop/";
var theFile = "test_swatch_change.pdf";
var f = new File(thePath + theFile);
var newFileName = theFile.replace(/\.pdf$/, "_Z.pdf");
var doc = app.open(f);
// 2)
doc.swatches.getByName('Kiss Cut').name = ('CutContourKiss-cut');
doc.swatches.getByName('Through Cut').name = ('CutContourThru-cut');
// 3)
var saveFile = new File(thePath + newFileName);
var saveOpts = new PDFSaveOptions();
doc.saveAs(saveFile, saveOpts);
// 4)
doc.close();
}
test();
embed() bug - rescales to original size
I have a script that finds goes to all placedItems and embeds them. My code is simple enough:
function embedAllImages(){
placedArt = app.activeDocument.placedItems;
if (placedArt < 0) {
return;
} else {
for ( var i = placedArt.length-1; i >= 0; i-- ) {
placedArt[i].embed();
}
}
}
In most cases it does as expected. However I found a strange case where after embedding, it scales the image to the original size.
Here's how to replicate the bug:
Create new .psd file in photoshop, can be one layer. Place it into illustrator twice, or duplicate it. Scale both images bigger or smaller.
Now run this simplified version of the script:
app.activeDocument.placedItems[0].embed();
app.activeDocument.placedItems[0].embed();
(note after embedding the first image, the next image gets index 0 since it's now the only placed item).
Now you'll see one of the images rescaled to it's original size.
If you do "placedItems[1].embed();" on the first line then it'll execute as expected. However I have found situations where even that resulted in the bug. So I can't use that as a work around.
Any ideas?
Thanks!
Misleading scripting guide? PathPoints index
Hello,
I've had trouble finding how to access the PathPoint positions today.
Apparently, the correct way to do it is by writing something like this: app.activeDocument.pathItems[itemIndex].pathPoints[pointIndex]
Which makes sense (pathPoints is an array) and it works fine and everything. Great.
Now why in the Illustrator Scripting Reference - JavaScript (CC 2015) PDF, page 138, this method is suggested: index(itemKey), type:number, returns:PathPoint, "Gets an element from the collection."?
I've tried using it and the only thing I got is this error message "app.activeDocument.pathItems[0].pathPoints.index is not a function" (with pathPoints.index(0) for example) which leads me to believe that there is no index method in the API... Is this correct or am I simply being very dumb and not using the method properly?
The reason I'm taking the time to write about this is because it seems I'm not the only one having this issue:
https://forums.adobe.com/thread/440700
EDIT:
Also, it seems pathPoints[pointIndex] works, but PathPoints[pointIndex], as it is written in the guide, doesn't.
Convert .eps file to .jpg or .pdf
I'm using Adobe to deal with .eps files.
My problem is to display graphic arts in "read only mode". That means when I'm done developing graphics in my .eps file, I want to display this graphics to other user without giving him option to edit it or delete it.
I'm trying to accomplish this true Visual Studio 2005, C# .net
Does somebody have any suggestions?
Creating Multi-Page PDF from a Layerd Illustrator file (script)
Often times when designing a logo I create different versions and variable options on layers. This can result in several layers in one Illustrator file. Is there an easy way or an existing script that will allow me to (with one click) create a multi-page PDF consisting of all the layers within my .ai file? The current method is turning on each layer, performing a save-as (PDF), then turning off said layer and turning on the next layer and repeating the task and so-on-and-so-forth, etc … It becomes tedious and quite often I save over the previous version, forgetting to re-name it or forget to perform a save on a certain layer. Can anyone help with some advice? I have never written my own script before but am not opposed to trying, where do I begin?
Any help is appreciated.
Cutting a circle
Hi all,
I need to make shapes like this based on a value for graph purposes - usually I would just create a cutting shape based on trig (this shape representing around 60%) and subtract it from the path - I have about 30 graphs to do and I need to base it on a variable, and I want to use script - I'm sure there must be a better way, and I'm hoping you guys have the answer.
Thanks in advance
Dave
batch converting .ai to .png in specific size
hi. i'm totally new to scripting and could use some help. i have a bunch of illustrator cs5 files (actually some of them might be older cs versions). they all have an artboard size of 200 x 200. i need to resize them to 700 x 700 and save them as png24 preserving transparency and keeping the same file name. is this possible? if so, any examples? thanks in advance!!!!
Script to convert CMYK color to PMS color
Hello All,
I have bunch of AI files that have thousands of objects with all different CMYK colors.
What I need to do is converting them into Pantone solid coated (PMS) colors.
I found a free script showing equivalent pantone color from the link blow.
10 Free and Extremely Useful Illustrator Scripts - Vectips
And trying to tweak to make the pantone color to be applied to the selected object.
In below script, I added line 178 and 179 like below.
activeDocument.selection[0].fillColor.typename = "SpotColor"; | ||
activeDocument.selection[0].fillColor.color = matchlist[0]; |
But it doesn't change the object's color.
Could you let me know how to do this?
I am not sure how to add script in this forum. Please download JS code from the link below.
https://www.dropbox.com/sh/qdxo1pi482h6yyx/AACeeo-ko6-ZPlzwfzpjZZQaa?dl=0
I am kind of new to scripting and wondering how to make this work.
If anyone can give me some advice, it would be great.
Thank you.
Possible to round font size if in decimal with AppleScript?
Hi,
Is it possible to automate the rounding of font sizes if they are in decimal form? I have a few thousand files I have to prepare for upload and they can't have font sizes such as 8.214 which several do. With AppleScript would it be possible to identify and then round up or down such font sizes?
Thanks!
How do I set http headers when using the BridgeTalk HttpConnection object?
Hi,
I am trying to make http post requests from within Illustrator ExtendScript (via BridgeTalk) and for the most part it is working. However, the documentation on using HttpConnection is non-existent and I am trying to figure out how to set http-headers. The HttpConnection object has both a requestheaders and responseheaders property so I suspect it is possible.
By default, the post requests are being sent with the Content-Type header "text/html", and I would like to override it so that I can use either "application/x-www-form-urlencoded" or "multipart/form-data".
Here is what I have so far:
var http = function (callback) {
var bt = new BridgeTalk();
bt.target = 'bridge' ;
var s = '';
s += "if ( !ExternalObject.webaccesslib ) {\n";
s += " ExternalObject.webaccesslib = new ExternalObject('lib:webaccesslib');\n";
s += "}\n";
s += "var html = '';\n";
s += "var http = new HttpConnection('http://requestb.in/1mo0r1z1');\n";
s += "http.method = 'POST';\n";
s += "http.requestheaders = 'Content-Type, application/x-www-form-urlencoded'\n";
s += "http.request = 'abc=123&def=456';\n";
s += "var c=0,t='';for(var i in http){t+=(i+':'+http[i]+'***');c++;}t='BEFORE('+c+'):'+t;alert(t);\n"; // Debug: to see what properties and values exist on the http object
s += "http.response = html;\n";
s += "http.execute() ;\n";
s += "http.response;\n";
s += "var t='AFTER:';for(var i in http){t+=(i+':'+http[i]+'***');}alert(t);\n"; // Debug: to see what properties and values have been set after executing
bt.body = s;
bt.onResult = function (evt) {
callback(evt);
};
bt.onError = function (evt) {
callback(evt);
};
bt.send();
};
Things to note:
1. If I try setting the requestheaders properties like in my code above, the request fails. If I comment it out, the request succeeds. The default value for requestheaders is undefined.
2. Examining the http object after a successful request, shows the reponseheaders properties to be set to: "Connection, keep-alive,Content-Length, 2,Content-Type, text/html; charset=utf-8,Date, Wed, 24 Jun 2015 09:45:40 GMT,Server, gunicorn/18.0,Sponsored-By, https://www.runscope.com,Via, 1.1 vegur". Before the request executes, the responseheaders is set to undefined.
If anyone could help me set the request headers (in particular the Content-Type header), I would be eternally grateful!
Thank you
UPDATE:
Using the ExtendScript SDK, I have discovered the responseheaders property is an array, of this format: ['Connection', 'keep-alive', 'Content-Length', 2, 'Content-Type', 'text/html' .........]
I have tried to set the requestheaders to the same format (I have tried both ['Content-Type', 'application/x-www-form-urlencoded'] and ['Connection', 'keep-alive', 'Content-Length', 2, 'Content-Type', 'application/x-www-form-urlencoded' .........]) with no luck
Can I get colors used in pattern using script?
I need to check every color used in a document. I'm looping all the pageItems and get each item's fillColor and strokeColor. However, if the fillColor/strokeColor is an instance of PatternColor, I don't find any way to get the colors used in the pattern. Any ideas? Or is it possible? Thanks.
fill color using a script.
I'm trying to create a script in CS5 mac os10.6.8 that will change the fill color of selected pathItems. I need a simple script that will change a selected pathItem to cmyk values 2,3,15,0. I will then select this script and implement the action in a batch of 600 files.
I wish this process could be recorded as an action but when I record the action "add new swatch" I have to manually input the cmyk values, which will take forever for a batch of over 600 files.
Script to open SVGs in a folder and save them to one multipage PDF
Hi.
I'm using Illustrator for work and I love it, I never needed scripts yet.
Now I have couple houndred svgs coming in per day,
I would like to have a script that opens every svg one by one in the selected directory and add them to a pdf
as pages of the same size and than save it.
Is this possible? How many files I could put in 1 pdf this way?
I'm using Illustrator CS5 on Win7 x64.
Thanks in advance.
Istvan
zOrderPosition error caused by 'duplicate' and 'move' methods
I created some paths and grouped them with a script. Then I selected an item below them and tried getting zOrderPosition of it with a script. And I got an error.
Is there a way to get rid of this?
Here is a code.
Please select a path and run test1 or test2 twice. You'll get an error at the second time.
(Tested with Ai CS3 and CC 2015)
Thanks.
function test1(){ // error (at the second time)
var lay = activeDocument.activeLayer;
var group = lay.groupItems.add();
var p1 = lay.pathItems.ellipse(100,100,10,10);
var p2 = p1.duplicate();
var p3 = p1.duplicate();
p2.move(group, ElementPlacement.PLACEATEND);
p3.move(group, ElementPlacement.PLACEATEND);
alert(activeDocument.selection[0].zOrderPosition); // error
}
function test2(){ // error (at the second time)
var lay = activeDocument.activeLayer;
var group = lay.groupItems.add();
var p1 = group.pathItems.ellipse(100,100,10,10);
var p2 = p1.duplicate();
alert(activeDocument.selection[0].zOrderPosition); // error
}
function test3(){ // NO error
var lay = activeDocument.activeLayer;
var group = lay.groupItems.add();
var p1 = lay.pathItems.ellipse(100,100,10,10);
var p2 = p1.duplicate();
p2.move(group, ElementPlacement.PLACEATEND);
alert(activeDocument.selection[0].zOrderPosition); // NO error
}
test1();
placedItem file (re)placement failure in Javascript
Greetings,
While scripting some automated placedItem replacements, I stumbled upon some issues with the feature failing in specific cases.
While most of them ended up working somehow at a later date, this one still fails:
Namely, the placing of an SVG image using a script. More specifically, I replace an existing graphic with one from an SVG image.
It doesn't matter whether I try to place it or replace an existing image, Adobe pops up with the following helpful error message:
'The file "TEST.svg" is in a format which cannot be placed'
Naturally, the test-image has been created using illustrator itself, and manually placing OR replacing the file through the interface 'just' works.
Should I be dropping this in a bug-report forum or is here ok?
Or are there specific demands for placeable SVGs?
Batching In Illustrator??
In PhotoShop CS3, you can select File/Automate/Batch, and run an Action on an entire folder. I don't see that option in Illustrator CS3? Is there a way to run an action on an entire folder?
I'm attempting to save many EPS images as PNG images, and would really like to retain "vector attributes" - is any of this possible???
Thanks for any help.
JavaScript to prompt user to save as PDF
I am making changes with code to the file. I want the user to be prompted to save as a .ai file first. I have that down. Now I am wanting to have the user immediately be prompted to save as a pdf with only the optimize for fast web view option selected. I believe it is an adobe preset of Smallest File Size.
The reason for wanting the prompt is because I want to save the files in 2 different locations.
Here is my code so far.....
var doc = app.activeDocument; // Save as .ai file var fileName = doc.fullName; var thisFile = new File(fileName); var saveFile = thisFile.saveDlg(); doc.saveAs (saveFile); // Save as .pdf file var pdfSaveOptions = new PDFSaveOptions(); pdfSaveOptions.pDFXStandard=PDFXStandard.PDFXNONE; pdfSaveOptions.compatibility = PDFCompatibility.ACROBAT5; pdfSaveOptions.preserveEditability = false; var pdfFile = new File(fileName); doc.saveAs(pdfFile, pdfSaveOptions);
AI CS4 Windows 7 64bit
Illustrator Layers to Classes ?
I need to export an SVG file whereas each path in the SVG file has it's own class.
I'm hoping renaming layers or groups then running a script in existence exports the SVG file, with the options available in IllustratorCC and when reading the SVG file each path or group has the class name given in the layer name. Similar to how Photoshop Generator works, or use to work, you'd append the layer name with another name which would be the class name for the path.
I'm unfamiliar with Grunt but was willing to learn due to this task which, correct me if I'm wrong, does exactly what I want, due to my unfamiliarity I was informed it doesn't do what I want ?
How to export PNG with 300 res using Applescript
How to export PNG with 300 res in Applescript
i want to copy a art and paste in new document and export as PNG to desktop location, & file name should be my previous doc were i copy file form. and saved file should be filename_PNG.png
set saveLocation to ((path to desktop) as string)
tell application "Adobe Illustrator"
if not frontmost then activate
if (count documents) > 0 then
set selectedItems to selection of current document
if selectedItems is not {} then
copy
set colorSpace to color space of current document
make new document with properties {color space:colorSpace}
paste
end if
end if
end tell
tell application "Adobe Illustrator"
tell document 1
set SelectedArt to visible bounds
set artboard rectangle of artboard 1 to SelectedArt
export current document to file newFilePath as PNG8 ¬
with options {class:PNG8 export options ¬
, color count:64 ¬ , color reduction:web ¬
, color dither:pattern dither ¬
, dither percent:50 ¬
, interlaced:true}
close current document saving no
end tell
end tell