Varied colors in the same text
Unembed All Images?
Hi everyone,
I was just wondering if there could be a "unembed all images" script out there. I have a pdf previously created in Word that I've imported into AI CC 2015 and need to create links out of all the embedded images in the doc.
Any help or reply is greatly appreciated,
Thanks!
Andy
Undefined PDF Presets in Illustrator CS5
I'm encountering a problem when attempting to retrieve a list of PDF preset names in both AppleScript and JavaScript. Here are the steps I'm performing:
1) Launch Illustrator
2) Run the following AppleScript:
tell application "Adobe Illustrator"
PDF presets
end tell
or JavaScript:
app.PDFPresetsList;
When I run the AppleScript, I receive an error: "Adobe Illustrator got an error: an Illustrator error occurred: 1128353350 ('FNAC')" number 1200. (Sometimes, 'ACVI' is listed instead of 'FNAC'.)
When I run the JavaScript, I receive: "Result: undefined"
If I retrieve Illustrator's properties via AppleScript, I can see that the PDF presets property appears as 'missing value'.
The only workaround I've found is to manually go to Illustrator and choose "Edit > Adobe PDF Presets", and then immediately click "OK" to close the window. Whatever this does seems to fix the problem, and if I run the scripts again, they produce the correct results until Illustrator is relaunched, at which time the problem begins again. I'm wondering if anyone else is experiencing this, and if anyone has come up with any other workarounds, preferably one that doesn't require manual work.
Much appreciated.
-Ben
"Isolation Mode" and Javascript.
Hi All,
Does anyone know of a way to get out of IsolationMode using Javascript?
I am trying to create a Duplicate of a Selection on a Tempory Layer.
The selection is often quickest to get to by Isolating.
Then running script.
I'm getting this error:
Error 9034: Cannot add a new layer as sibling to 'Isolation Mode' synthetic layer.
-> tempLayer = app.activeDocument.layers.add();
I also have this issue with another Script I use to Save Artwork.
If Isolation Mode is active when script is run, file is saved with non-isolated sections "Dimmed"
Would be nice to "Idiot Proof" the code a little more by getting out of Isolation mode if need be before saving.
Snippet of save code below:
saveName = new File(FilePathAndName); saveOpts = new PDFSaveOptions(); saveOpts.compatibility = PDFCompatibility.ACROBAT5; saveOpts.generateThumbnails = true; saveOpts.preserveEditability = true; app.activeDocument.saveAs( saveName, saveOpts );
Fingers Crossed there is a way to access "Isolation Mode" using Javascript.
Both scripts are too much for an action.
I can't run action from Javascript... can I? (boo)
and I realy don't want to go down the path of running JS from an Action, then calling VB to call a different action bla bla.
am using CS6 with CC coming soon...
Thanks in advance...
Loop Place Items URL for replace
Hey All,
Trying to write a script that can replace placedItems by URL but having trouble with getting the loop to return the url to me. This is what I have so far. Can someone please show me what I am doing wrong.
function replaceByURL(){
var idoc = app.activeDocument;
var server = "/Users/Desktop";
var file = File (server + "/" + "graphic.pdf");
placedGraphic = idoc.placedItems;
for (i=0 ; i<placedGraphic.length ; i++ ) {
alert(placedGraphic[i].url); // This will eventually replace placedItem by url
}
};
replaceByURL()
How to reflect in script?
I want the equivalent of choosing Object > Transform > Reflect, across the Vertical axis. How would I do this with JavaScript?
Thanks,
Max
Find a text box using note and format text within?
Hello, I must do a repetitive task and think scripting will help me. I need to find pageItems by their "note" and then format the text within both generically (text by case sensitivity) and specifically (words by font weight). Please see the attached screen capture. I work in Illustrator CC 2018. I'd prefer to control the font through the script as opposed to applying character styles, if possible. At some point I may need to control the font size and leading through this script as well. I tried to use the code snippets from "Select Note and apply Style" but was unsuccessful in my attempts. I would rather not use a prompt, in my case the notes are static as are the words which need formatting.
Any assistance would be appreciated.
Illustrator batch export to same folder
Have a folder containing several subfolders, each folder has a few EPS files. Ran a batch with an export script I created.
Works great except all files are being exported into one folder.
How do I get each to be saved into their respective folders, without interruption?
Script to determine if Gaussian blur is set in illustrator
I have some illustrator documents that need scripting tasks performed on them. Not all of them need the same tasks, however, and I would like to determine if a Gaussian blur is set on a particular layer (and its properties) in order to determine whether to run certain other functions. I am having trouble locating the correct object or property to look for to get this information in my script. I have tried looking in textFrames, for example:
var textFrame = app.activeDocument.textFrames[0];
In my test document I know this text frame represents text with a blur set on it. Where do I go to get the properties of this blur and the information that the blur is set?
The initial value of mValueTX and mValueTY
Hello.
Does the initial values of mValueTX and mValueTY of the object just generated refer the upper left coordinates of the document's largest area? For example, TextFrameItem and PlacedItem.
I want to get the coordinates of the document's largest area easily. Do you have any sugesstions?
I referred to here.
This script worked fine on Illustrator CS6, CC2015, CC2017, CC2018 (for mac).
Is this correct?
function getLargestBounds() { var tempLayer, tempText, left, top, LARGEST_SIZE = 16383; if (!app.documents.length) { return; } tempLayer = app.activeDocument.layers.add(); tempText = tempLayer.textFrames.add(); left = tempText.matrix.mValueTX; top = tempText.matrix.mValueTY; tempLayer.remove(); return new Rect( left, top, left + LARGEST_SIZE, top + LARGEST_SIZE ); } var rect = getLargestBounds(); // cover the whole area. app.activeDocument.pathItems.rectangle(rect[1], rect[0], 16383, 16383);
Sorting 2 Arrays
I am pulling 2 arrays and having them be reformatted and spit out next to the artboard. I can't seem to get the first column of names to sort. Then once they are sorted I need the second column to sort with the first column.
Here is my script....
#target illustrator-22 var doc = app.activeDocument; var allLayers = doc.layers; var layerRename = "Grid Location"; var triggerAlert = 0; for (var i = 0; i < allLayers.length; i++) { if (allLayers[i].name == "42 Pg Grid Location" || allLayers[i].name == "36 Pg Grid Location" || allLayers[i].name == "30 Pg Grid Location" || allLayers[i].name == "24 Pg Grid Location" || allLayers[i].name == "20 Pg Grid Location" || allLayers[i].name == "16 Pg Grid Location" || allLayers[i].name == "12 Pg Grid Location" || allLayers[i].name == "8 Pg Grid Location" || allLayers[i].name == "4 Pg Grid Location") { allLayers[i].name = layerRename; triggerAlert++; } else if (allLayers[i].name == layerRename) { triggerAlert++; } } if (triggerAlert == 1) { function findGrid() { var d = activeDocument, ps = d.layers['Grid Location'].pathItems, l = ps.length, o = 'ABCDEFGHIJKLMNOPQRST...', W, H, rows = columns = 1, origin = d.rulerOrigin, /*newOrigin = new Array(2),*/ newOrigin = new Array(0, 0), t, b, center, gx, gy, i = 0; for (; i < l; i++) { if (ps[i].width == 0) { columns++; !newOrigin[1] && newOrigin[1] = origin[1] + ps[i].geometricBounds[3]; !H && H = ps[i].height; } if (ps[i].height == 0) { rows++; !newOrigin[0] && newOrigin[0] = origin[0] + ps[i].geometricBounds[2]; !W && W = ps[i].width; } } d.rulerOrigin = newOrigin; W = W / columns; H = H / rows; t = app.selection[z]; b = t.geometricBounds; center = [b[0] + (b[2] - b[0]) / 2, b[1] + (b[3] - b[1]) / 2]; gx = Math.abs(center[0]) / W; gy = Math.abs(center[1]) / H; d.rulerOrigin = origin; xCoor = -50; yCoor = 0; createGridText = d.textFrames.add(); createGridText.position = [xCoor, yCoor = (inc -= 20)]; createGridText.contents = '' + o[Math.ceil(gy - 1)] + "-" + Math.ceil(gx); } inc = 0; incTwo = 0; d = activeDocument; for (var z = 0; z < selection.length; z++) { xC = -350; yC = 0; createComponentText = d.textFrames.add(); createComponentText.position = [xC, yC = (incTwo -= 20)]; createComponentText.contents = selection[z].contents; findGrid(); } var doc = app.activeDocument var allText = doc.textFrames; formatCompTable(); removeLamps(); removeUnderscores(); /* CODE TO FORMAT SWITCH, RELAY, SOLENOID, SENSOR, GROUND, ETC. */ function formatCompTable() { var aCon; for (var i = 0; i < allText.length; i++) { //alert(allText[i].layer); //if (allText[i].layer == "[Layer Hypertext]"){ aCon = allText[i].contents; if (aCon.match(/_SWITCH|SWITCH_|SWITCH/) != null) { aCon = aCon.replace(/_SWITCH|SWITCH_|SWITCH/, ""); aCon = "SWITCH - " + aCon; allText[i].contents = aCon; } else if (aCon.match(/_SW(?!\w)|SW_/) != null) { aCon = aCon.replace(/_SW|SW_/, ""); aCon = "SWITCH - " + aCon; allText[i].contents = aCon; } else if (aCon.match(/_RLY|RLY_/) != null) { aCon = aCon.replace(/_RLY|RLY_/, ""); aCon = "RELAY - " + aCon; allText[i].contents = aCon; } else if (aCon.match(/RELAY/) != null) { aCon = aCon.replace(/RELAY/, ""); aCon = "RELAY - " + aCon; allText[i].contents = aCon; } else if (aCon.match(/_FUSE|FUSE_/) != null) { aCon = aCon.replace(/_FUSE|FUSE_/, ""); aCon = "FUSE - " + aCon; allText[i].contents = aCon; } else if (aCon.match(/_SOL(?!\w)|SOL_|SOL(?!\w)/) != null) { aCon = aCon.replace(/_SOL|SOL_|SOL/, ""); aCon = "SOLENOID - " + aCon; allText[i].contents = aCon; } else if (aCon.match(/_SNSR|SNSR_/) != null) { aCon = aCon.replace(/_SNSR|SNSR_/, ""); aCon = "SENSOR - " + aCon; allText[i].contents = aCon; } else if (aCon.match(/_SENSOR|SENSOR_/) != null) { aCon = aCon.replace(/_SENSOR|SENSOR_/, ""); aCon = "SENSOR - " + aCon; allText[i].contents = aCon; } else if (aCon.match(/GND($^)/) != null) { aCon = aCon.replace(/GND/, ""); aCon = "GROUND - " + aCon; allText[i].contents = aCon; } else if (aCon.match(/_GROUND|GROUND_/) != null) { aCon = aCon.replace(/_GROUND|GROUND_/, ""); aCon = "GROUND - " + aCon; allText[i].contents = aCon; } else if (aCon.match(/GND/) != null) { aCon = aCon.replace(/GND/, ""); aCon = "GROUND - " + aCon; allText[i].contents = aCon; } else if (aCon.match(/_ALARM|ALARM_/) != null) { aCon = aCon.replace(/_ALARM|ALARM_/, ""); aCon = "ALARM - " + aCon; allText[i].contents = aCon; } /*else if (aCon.match(/_ECM|ECM_/) != null) { aCon = aCon.replace(/_ECM|ECM_/, ""); aCon = "CONTROL - " + aCon; allText[i].contents = aCon; }*/ else if (aCon.match(/_CONTROL|CONTROL_/) != null) { aCon = aCon.replace(/_CONTROL|CONTROL_/, ""); aCon = "CONTROL - " + aCon; allText[i].contents = aCon; } else if (aCon.match(/CTRL/) != null) { aCon = aCon.replace(/CTRL/, ""); aCon = "CONTROL - " + aCon; allText[i].contents = aCon; } else if (aCon.match(/RESISTOR/) != null) { aCon = aCon.replace(/RESISTOR/, ""); aCon = "RESISTOR - " + aCon; allText[i].contents = aCon; } else if (aCon.match(/_CAN|CAN_/) != null) { aCon = aCon.replace(/_CAN|CAN_/, ""); aCon = "RESISTOR - CAN " + aCon; allText[i].contents = aCon; } //else if (aCon.match(/RES(?=\s)|RES_/) != null) { else if (aCon.match(/_RES|RES_/) != null) { aCon = aCon.replace(/_RES|RES_/, ""); aCon = "RESISTOR - " + aCon; allText[i].contents = aCon; } //else if (aCon.match(/MOTOR|MOT(?=\s)|MOT_/) != null) { else if (aCon.match(/_MOTOR|MOTOR_/) != null) { aCon = aCon.replace(/_MOTOR|MOTOR_/, ""); aCon = "MOTOR - " + aCon; allText[i].contents = aCon; } } } } else { alert("Couldn't find the proper Grid Location layer format. \nMake sure the layer with your grid locations is labeled...\nGrid Location"); } /* CODE TO FORMAT LAMPS */ function removeLamps() { var aCon; for (var i = 0; i < allText.length; i++) { aCon = allText[i].contents; if (aCon.match(/_LAMP|LAMP_/) != null) { aCon = aCon.replace(/_LAMP|LAMP_/, ""); aCon = "XXXX LAMPS - " + aCon; allText[i].contents = aCon; } else if (aCon.match(/_LTS|LTS_/) != null) { aCon = aCon.replace(/_LTS|LTS_/, ""); aCon = "XXXX LAMPS - " + aCon; allText[i].contents = aCon; } } } /* CODE TO REMOVE UNDERSCORES */ function removeUnderscores() { var searchString = /_/g; var replaceString = " "; for (var i = 0; i < allText.length; i++) { var thisTextFrame = allText[i]; var newString = thisTextFrame.contents.replace(searchString, replaceString); if (newString != thisTextFrame.contents) { thisTextFrame.contents = newString; } } } var theContents; for (i = 0; i < allText.length; i++) { theContents = allText[i].contents; theContents = myTrim(theContents); allText[i].contents = theContents; } removeDoubleSpaces(); function myTrim(x) { return x.replace(/^\s+|\s+$/gm, ''); } function removeDoubleSpaces() { var searchString = / /g; var replaceString = " "; for (var i = 0; i < allText.length; i++) { var thisTextFrame = allText[i]; var newString = thisTextFrame.contents.replace(searchString, replaceString); if (newString != thisTextFrame.contents) { thisTextFrame.contents = newString; } } } function removeDoubleDashes() { var searchString = /--/g; var replaceString = "-"; for (var i = 0; i < allText.length; i++) { var thisTextFrame = allText[i]; var newString = thisTextFrame.contents.replace(searchString, replaceString); if (newString != thisTextFrame.contents) { thisTextFrame.contents = newString; } } } removeDoubleDashes(); alert("Your component table has been successfully created!");
Here is a test file....
A couple bonus items I would love to do.... no selection needed. Anything that is on the Hypertext layer is what would get used for column 1. Would also love to spit out a .csv file to import into Excel.
This may be too much to ask at one time. If so.... I apologize. Any help would be appreciated though!
Prompt box to End Script Early?
I have a somewhat lengthy script that can take a while to get through once it gets started, is there a way I could get a prompt box to pop-up at the beginning of the script and remain in place throughout it's execution, that could be used to end the script in the middle of it running? Pretty much a 'Cancel' button. Would I have to radically alter the format of the original script to make something like that work? Right now the bulk of the script has a number of export commands all housed in a try()/catch().
Can't get visible bounds of selection
I am having a frustrating time starting off with AppleScript in Illustrator. I have one rectangle selected on a page and I want to get the visible bounds. I run the following script:
tellapplication "Adobe Illustrator"
setmyselectiontotheselection
ifmyselectionis {} then
display dialog "Choose something"
endif
set theBounds to visible bounds of myselection
endtell
When I try to run it, "bounds" is highlighted and I get error:
Expected end of line, etc. but found property.
What am I doing wrong?
Encoding question
I have been using Andy VanWagoner's CSV parse for a long time now, it always worked fine with 'regular' csv data, but recently I'm working with a CSV file provided by clients which contain typographic quotes.
The thing is, I'm able to read the files, and write these files with all characters preserved OK. However, with this file when the data is parsed as CSV and then stringified, then each typographic character turns into the weird characters.
I'm looking to find more information on this, and what's the reason for the characters being so converted in the code?
I am okay with doing what I'm doing right now :
Using this array to convert the characters which result after being parsed with the parser.
["Äú", "“"],
["Äù", "”"],
["Äô", "’"],
Of course the array is incomplete and I am not sure what we call either set of these when it comes to their encoding kind. What is "Äú" ?
Does anyone have a good way to deal with this to include other characters like this which may eventually come up?
Why are Adobe scripting docs like for Illustrator vague on Applescript's file open?
From the Adobe scripting reference for Applescript, for Illustrator (I believe is same for other products too), I see code example snippets like:
on openFile(fileToOpen)
tell application "Adobe Illustrator"
activate
open POSIX file fileToOpen as alias with options
end tell
end openFile
Why does it leave us to figure out the (string) value of fileToOpen? Understandable that that is Applescript specific, but that is more work for those of us not familiar with Applescript to do more research.
Is "as alias" really needed? I'm having trouble with this. Omitting "as alias" gets Applescript error: "Adobe Illustrator got an error: AppleEvent handler failed." Keeping "as alias" results error saying it can't create alias to the path, which for some reason looks like it's formatted as Applescript path even though specified as POSIX (e.g. ":~:Documents:Temp:someFile.ai" instead of "~/Documents/Temp/someFile.ai").
Tried the straightforward example
open POSIX file "~/Documents/Temp/someFile.ai"
as well as
set pfile to "~/Documents/Temp/someFile.ai" as POSIX file
open pfile without options
set pfilepath to "~/Documents/Temp/someFile.ai"
set pfile to POSIX file pfilepath
open pfile as alias without options
nothing seems to work so far. Such a pain.
Adjust dashes is not possible via Scripting (SVG export dashes problem)
Hello,
it is not possible to use this function in the Stroke menu in Illustrator 2015 via Scripting:
This is the reason, why I use this Javascript function:
s.h's page : Scripts for Adobe Illustrator CS
Now I have a Problem, when I export a drawing in SVG format.
I have today a discussion in the Illustrator forum:
Export SVG changed the dashed line
The end of the discussion was, that the SVG export works, when I use the internal Illustrator function.
Unfortunately the SVG export does not work with the Javascript function.
I use the Javascript function in Illustrator. And the drawing looks fine in Illustrator:
But when I export the drawing in SVG Format, then center line is wrong:
When I adjust the dashes with the internal Illustrator function, then the SVG export looks fine.
Note: The drawing is imported in Illustrator from DWG format.
What can I do?
Can I use the internal Illustrator function in the newest Version via Scripting?
Is there an update of the Javascript function?
Any other workaround possible?
Best regards
Harald
PageItem name in Layers panel not refreshing
I'm working on a script that finds certain PageItems and changes their name. Unfortunately, the item name in the 'Layers' panel doesn't refresh right away - only after closing&expanding the layers tree to which the item belongs.
Is there any way to make Illustrator refresh this panel?
Check if Plug-in is Active or Installed?
I have a script that I'm trying to create that runs fine as long as a certain plug-in is active (Esko Studio Designer/Visualizer), but if the script runs without the plug-in being active, it breaks Illustrator and crashes out. Our office has this plug-in on a floating license with only a set number of users, so only a few people can have it active at one time. So when somebody isn't using it, they'll just deactivate it from their machine. Though if we're having network issues, sometimes it just goes off unbeknownst to the user, so potentially it's unpredictable.
Is there a way to insert a code into my javascript that I already have that could check for whether the plug-in is active, and if it's not, throw an error message (instead of crashing Illustrator)?
"Save A Copy" scripting problem
I'm trying to create a "Save As PDF" script for Illustrator that will allow me to keep my active document as an Illustrator (.AI) file open.
In my workflow, I need to create compressed PDF version of my Illustrator file for clients, WHILE I'm working on an Illustrator file. In other words, I need to keep the .AI file open and have the .PDF file saved in the background.
Currently this is how I do this:
1. Choose "Save A Copy..."
2. Choose PDF
3. Choose PDF Preset from the drop-down menu.
4. Use the keyboard to delete " copy" which is automatically appended.
5. Choose "Save PDF"
Of course I can easily just choose "Save As.." and choose pdf, but then my file is no longer an Illustrator (.ai) file.
I've been able to code a script which will automatically save my document as a pdf with a specific preset but it only works on the "Save As..." command. I need it to work on the "Save A Copy..." command. If I could just figure out a way to automatically remove the " copy" suffix that's automatically appended to the filename it would be a breeze.
Can you assist me in figuring this out?
Java Script for first letter caps
Is there a java script that will ensure that my sentence is typed out with all of the first letter of each word is typed in a capital letter? I know how to make all of the words capital, but I am looking for a way to make just the first letter of each word a capital letter.
for example: How To Train Your Dragon
Thank you.