Resize Artboard
Export file as a DXF
My script is working nice until I try to export my document. I am trying to export my document as a DXF file. Using the Illustrator CS6 Scripting Reference I am using the TIFF export as a reference as there are no examples for exporting as a DXF (my luck!). This is what I have in VBscript. With this script I get the following error on the second to last line:
"Illegal argument - argument 2 - Enumerated value expected"
As you can see I do have one: "0" so I suspect the error lies elsewhere in the code? I'll take a JavaScript example if you are not into VBscript since the two look very similar and I think I can adapt it.
Set App = CreateObject("Illustrator.Application")
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim dest
dest = "S:\SOCAL\Section_32\Veg DXFs LC\SOCAL_CK67_pineLC"
Set DXFexport = CreateObject("Illustrator.ExportOptionsAutoCAD")
If App.Documents.Count > 0 Then
Set docRef = App.ActiveDocument
Call docRef.Export (dest, 0, DXFexport) ' 0 = aiDXF
End If
Can you set a file to "self destruct" after a set period of time?
Hi!
I have someone interested in using a script that I had made. I would like to let them use it but I want to have some control over the period of time they are able to. My plan is to encrypt the script and hopefully set it to self destruct after a year, so they need a new file from me to continue using it. This way, if we stop doing business they can no longer use the script.
Is there a simple way to do something like this?
Thanks!
How do I access the values inside the Color panel or know whether it's currently set to stroke or fill?
Hello, very new to scripting. I know that I can assign a color to selected objects:
app.documents.add(DocumentColorSpace.RGB) // get the active document var doc = app.activeDocument; // verify there is a document and at least one shape, // enumerate through each pathItem and assign a given color to fill if ( app.documents.length > 0 && app.activeDocument.pathItems.length > 0) { var newColor = new RGBColor; newColor.red = 255; newColor.green = 0; newColor.blue = 0; for (var a=0; a<app.selection.length; a++) { try { var currentSelection = app.selection[a]; // But how would I know whether Stroke or Fill is active here? currentSelection.fillColor = newColor; } catch (e){alert(e) } } }
With AutoHotKey, I can use ControlGetText on the input element of the Color Panel ("Edit 15") to directly interact and easily apply colors by submitting a new value within it, which accurately sends it as a stroke or fill depending on which is currently toggled. Is there any way to replicate this and have access to the current/active value within this panel?
How do I cut and paste a group to a new document via actions?
I wrote a script to cut and paste groups in the first layer of a document, into new documents to isolate each group. While it works great via ESTK, and running as a script menu item, it cuts the groups from the original document, but will not paste them into newly created documents when running this menu item through an action. Is there a way to get this to run properly?
origDoc = app.activeDocument; length = origDoc.layers[0].groupItems.length; for(i=length; i>0; i--){ origDoc.activate(); app.executeMenuCommand('deselectall'); origDoc.layers[0].groupItems[i-1].selected = true; app.cut(); newDoc = app.documents.add(); newDoc.activate(); app.paste(); }
Skipping the loops, even trying to run it only on the first group in a layer will not work as an action:
origDoc = app.activeDocument; origDoc.activate(); app.executeMenuCommand('deselectall'); origDoc.layers[0].groupItems[0].selected = true; app.cut(); newDoc = app.documents.add(); app.paste();
The other odd behavior is that the original document still seems to have items within the group selected after running the script even if I try to deselect all. Running the script again, the new documents show up is empty.
Can't seem to find some sample scripts
I'm not sure if I'm looking in the wrong spot, or didn't download the full SDK, or I'm just inept.
In the help menu of the ESTK, is a Creative Cloud JavaScript Tools Guide, and it mentions several sample scripts:
Code examples for ScriptUI
The sample code distributed with the Adobe ExtendScript SDK includes code examples that specifically demonstrate different ways of building and populating a ScriptUI dialog.
One in particular listed I'd like to peek at, "ColorPicker.jsx", but I can't seem to find any of them.
Resolution check in illustrator
How to check the raster image resolution in illustrator through script?
A list of Illustrator menu commands we can call from JavaScript.
app.executeMenuCommand(StringFromListBelow);
actualsize
Add Anchor Points2
AddArrowHeads2
Adjust Colors Dialog
Adjust3
Adobe Action Palette
Adobe Actions Batch
Adobe AI Device center
Adobe AI Save For Web
Adobe Apply Last Effect
Adobe Art Style Plugin Other libraries menu item
Adobe Bridge Browse
Adobe BrushManager Menu Item
Adobe Color Palette
Adobe Color Palette Secondary
Adobe Default Workspace
Adobe Flattening Preview
Adobe Gradient Palette
Adobe Harmony Palette
Adobe Illustrator Find Font Menu Item
Adobe Illustrator Smart Punctuation Menu Item
Adobe Last Effect
Adobe LinkPalette Menu Item
Adobe Manage Workspace
Adobe Minimal Workspace
Adobe New Fill Shortcut
Adobe New Stroke Shortcut
Adobe New Style Shortcut
Adobe New Swatch Shortcut Menu
Adobe New Symbol Shortcut
Adobe Optical Alignment Item
Adobe Paragraph Styles Palette
Adobe Save a Version
Adobe Save Workspace
Adobe Stroke Palette
Adobe Style Palette
Adobe SVG Interactivity Palette
Adobe Swatches Menu Item
Adobe Symbol Palette
Adobe Symbol Palette Plugin Other libraries menu item
Adobe Transparency Palette Menu Item
Adobe Update Link Shortcut
Adobe Variables Palette Menu Item
AdobeAlignObjects2
AdobeBrushMgr Other libraries menu item
AdobeBuiltInToolbox1
AdobeCheatSheetMenu
AdobeLayerPalette1
AdobeLayerPalette2
AdobeLayerPalette3
AdobeNavigator1
AdobeNavigator2
AdobePathfinderPalette1
AdobeSwatch_ Other libraries menu item
AdobeTransformObjects1
AI Bounding Box Toggle
AI Magic Wand
AI Object Mosaic Plug-in3
AI Place
AI Reset Bounding Box
ai_browse_for_script
AISlice Clip to Artboard
AISlice Combine
AISlice Create from Guides
AISlice Create from Selection
AISlice Delete All Slices
AISlice Divide
AISlice Duplicate
AISlice Feedback Menu
AISlice Lock Menu
AISlice Make Slice
AISlice Release Slice
AISlice Slice Options
alternate glyph palette plugin
alternate glyph palette plugin 2
Appearance of Black 1
Apply Last Filter
areatextoptions
arrangeicon
artboard
assignprofile
average
avgAndJoin
bringAllToFront
Brush Strokes menu item
cascade
centerAlign
Character Styles
Check Spelling
cleanup menu item
clear
clearguide
clearTrack
clearTypeScale
Clipping Masks menu item
close
closeAll
color
Colors3
Colors4
Colors5
Colors6
Colors7
Colors8
Colors9
compoundPath
control palette plugin
convertlegacyText
convertlegacyText1
convertlegacyText2
convertlegacyText3
convertlegacyText4
copy
Create Envelope Grid
cut
Define Pattern Menu Item
deselectall
discretHyphen
Distort2
doc-color-cmyk
doc-color-rgb
DocInfo1
document
DropShadow2
Dynamic Text
edge
Edit Custom Dictionary...
Edit Envelope Contents
editGraphData
editMask
EditOriginal Menu Item
editview
enterFocus
Envelope Options
exitFocus
Expand as Viewed
Expand Envelope
Expand Planet X
Expand Tracing
Expand3
expandStyle
export
faceSizeDown
faceSizeUp
File Handling & Clipboard 1
File Info
Find and Replace
Find Blending Mode menu item
Find Fill & Stroke menu item
Find Fill Color menu item
Find Link Block Series menu item
Find Next
Find Opacity menu item
Find Reselect menu item
Find Stroke Color menu item
Find Stroke Weight menu item
Find Style menu item
Find Symbol Instance menu item
fitall
fitHeadline
fitin
Flash Text
FlattenTransparency1
Gradient Feedback
graphDesigns
group
guidegridPref
helpcontent
hide
hide2
hideApp
hideOthers
highlightFont
highlightFont2
hyphenPref
ink
Input Text
internal palettes posing as plug-in menus-attributes
internal palettes posing as plug-in menus-character
internal palettes posing as plug-in menus-info
internal palettes posing as plug-in menus-opentype
internal palettes posing as plug-in menus-paragraph
internal palettes posing as plug-in menus-tab
Inverse menu item
join
justify
justifyAll
justifyCenter
justifyRight
KBSC Menu Item
keyboardPref
Knife Tool2
Last Filter
leftAlign
Live 3DExtrude
Live 3DRevolve
Live 3DRotate
Live AddArrowHeads2
Live Color Dialog
Live Deform Arc
Live Deform Arc Lower
Live Deform Arc Upper
Live Deform Arch
Live Deform Bulge
Live Deform Fish
Live Deform Fisheye
Live Deform Flag
Live Deform Inflate
Live Deform Rise
Live Deform Shell Lower
Live Deform Shell Upper
Live Deform Squeeze
Live Deform Twist
Live Deform Wave
Live DropShadow2
Live Ellipse
Live Feather
Live Free Distort
Live Inner Glow
Live Offset Path
Live Outer Glow
Live Outline Object
Live Outline Stroke
Live Pathfinder Add
Live Pathfinder Crop
Live Pathfinder Divide
Live Pathfinder Exclude
Live Pathfinder Hard Mix
Live Pathfinder Intersect
Live Pathfinder Merge
Live Pathfinder Minus Back
Live Pathfinder Outline
Live Pathfinder Soft Mix
Live Pathfinder Subtract
Live Pathfinder Trap
Live Pathfinder Trim
Live Pucker & Bloat
Live Rasterize
Live Rasterize Effect Setting
Live Rectangle
Live Roughen
Live Round3
Live Rounded Rectangle
Live Scribble and Tweak
Live Scribble Fill
Live Transform
Live Twist
Live Zig Zag
lock
lock2
lockguide
LowerCase Change Case Item
Make and Convert to Live Paint
Make and Expand
Make Envelope
make mesh
Make Planet X
Make Text Wrap
Make Tracing
Make Warp
makeguide
makeMask
Marge Planet X
minimizeWindow
navigateToNextDocument
navigateToNextDocumentGroup
navigateToPreviousDocument
navigateToPreviousDocumentGroup
new
newFromTemplate
newview
newwindow
noCompoundPath
OffsetPath2
OffsetPath3
open
outline
Overprint2
pagetiling
Paint Tracing
paste
pasteBack
pasteFront
pasteInAllArtboard
pasteInPlace
PathBlend Expand
PathBlend Make
PathBlend Options
PathBlendRelease
PathBlend Replace Spine
PathBlend Reverse Spine
PathBlend Reverse Stack
PDF Presets
Planet X Options
pluginPref
preference
preview
Print Presets
proofColors
proof-custom
proof-document
proof-mac-rgb
proof-monitor-rgb
proof-win-rgb
Punk2
quit
raster
Rasterize 8 menu item
redo
Registration...
Release Envelope
Release Planet X
Release Text Wrap
Release Tracing
releaseCropMarks
releaseguide
releaseMask
releaseThreadedTextSelection
Remove Anchor Points menu
removeThreading
repeatPathfinder
Replace Colors Dialog
revert
rightAlign
Roughen3
Round3
Rows and Columns....
ruler
rulerCoordinateSystem
Saturate3
save
Save for Office
saveacopy
saveas
saveasTemplate
Scribble3
selectall
selectallinartboard
Selection Hat 1
Selection Hat 10
Selection Hat 11
Selection Hat 2
Selection Hat 3
Selection Hat 4
Selection Hat 5
Selection Hat 6
Selection Hat 7
Selection Hat 8
Selection Hat 9
selectionPref
sendBackward
sendForward
sendToBack
sendToFront
Sentence case Change Case Item
setBarDesign
setCropMarks
setGraphStyle
setIconDesign
Show Gaps Planet X
Show Perspective Grid
Show Preprocessed Image
showAll
showAllWindows
ShowArtwork
showgrid
showguide
showHiddenChar
ShowNoArtwork
ShowNoImage
ShowOriginalImage
ShowPaths
ShowPathsAndTransparentArtwork
showtemplate
ShowTransparentImage
simplify menu item
sizeStepDown
sizeStepUp
snapgrid
Snapomatic on-off menu item
snappoint
snapPref
spacing
Stray Points menu item
Style Palette
SWFPresets
switchSelTool
switchUnits
systemInfo
Text Objects menu item
Text Wrap Options...
textpathtype3d
textpathtypeGravity
textpathtypeOptions
textpathtypeRainbow
textpathtypeSkew
textpathtypestairs
textthreads
threadTextCreate
tile
Title Case Change Case Item
toggleAutoHyphen
toggleLineComposer
Tracing Options
TracingPresets
tracking
Transform3
transformagain
transformmove
transformreflect
transformrotate
transformscale
transformshear
Transparency Presets
TransparencyGrid Menu Item
TrimMark2
Twirl Tool2
type-horizontal
type-vertical
undo
ungroup
unitundoPref
unlockAll
UpperCase Change Case Item
userInterfacePref
view1
view10
view2
view3
view4
view5
view6
view7
view8
view9
Welcome screen menu item
ZigZag2
zoomin
zoomin2
zoomout
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.
How to embed multiple images
Hello!
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.
Any ideas?
Is there a way to batch rename artboards in Illustrator CC?
Is there a way to batch rename artboards in Illustrator CC?
I have 20 different artbords that i want to rename with a specific name and number!
/Pål
Anti-aliasing Type Optimized/Art Optimized on PNG export
Hello there,
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?
Many thanks,
D
Split a string into multiple lines based on length
I am allowing the user to input a description. What I am needing is to split up the string they input based on 27 characters.
So if their description is less than 27 characters....
It is a single string and needs to alert them of that.
If their description is more than 27 but less than 54 characters....
I need it to find the space closest to the 27th character, then split the string into 2 lines
If their description is more than 54 but less than 81 characters....
I need it to find the space closest to the 54th character, then split the string into 3 lines
If their description is more than 81 but less than 108 characters....
I need it to find the space closest to the 81st character, then split the string into 4 lines
If their description is more than 108 characters....
Alert that it is really long
Here is a section of code I am working with
for (z = 0; z < theDocVariables.length; z++) { // Start finding variables here if (theDocVariables[z].name == "coverPageDecriptionLineOne") { if (getText(titleDescription).length < 27){ alert("single line"); } if (getText(titleDescription).length > 27 && getText(titleDescription).length < 54){ alert("two line"); } if (getText(titleDescription).length > 54 && getText(titleDescription).length < 81){ alert("three line"); } if (getText(titleDescription).length > 81 && getText(titleDescription).length < 108){ alert("four line"); } if (getText(titleDescription).length > 108){ alert("that's a long freakin description"); } alert("Your title is " + getText(titleDescription).length + " characters in it"); }
Render swatch Legend Script
I was wondering if someone could help me edit this Script Written by John Wundes. Its almost perfect for what i need, but my problem is the text box inside of the swatch when it is rendered is to small. Ideally i'd like it to be 90% the size of the actual swatch. I've copied and pasted it here if someone could help i'd greatly appreciate it. I tried asking John on his Blog a few times but i haven't gotten any response. Also i'd like to delete the CMYK values that it returns with just the PMS name only.
Render Swatch Legend v1.1 -- CS, CS2, CS3, CS4, CS5
//>=--------------------------------------
//
// This script will generate a legend of rectangles for every swatch in the main swatches palette.
// You can configure spacing and value display by configuring the variables at the top
// of the script.
// update: v1.1 now tests color brightness and renders a white label if the color is dark.
//>=--------------------------------------
// JS code (c) copyright: John Wundes ( john@wundes.com ) www.wundes.com
// copyright full text here: http://www.wundes.com/js4ai/copyright.txt
//
//////////////////////////////////////////////////////////////////
doc = activeDocument,
swatches = doc.swatches,
cols = 10,
displayAs = "CMYKColor", //or "RGBColor"
rectRef=null,
textRectRef=null,
textRef=null,
rgbColor=null,
w=150;
h=150,
h_pad = 100,
v_pad = 100,
t_h_pad = 100,
t_v_pad = 100,
x=null,
y=null,
black = new GrayColor(),
white = new GrayColor()
;
black.gray = 100;
white.gray = 0;
activeDocument.layers[0].locked= false;
var newGroup = doc.groupItems.add();
newGroup.name = "NewGroup";
newGroup.move( doc, ElementPlacement.PLACEATBEGINNING );
for(var c=2,len=swatches.length;c<len;c++)
{
var swatchGroup = doc.groupItems.add();
swatchGroup.name = swatches[c].name;
x= (w+h_pad)*(c% cols);
y=(h+v_pad)*(Math.floor((c+.01)/cols))*-1 ;
rectRef = doc.pathItems.rectangle(y,x, w,h);
rgbColor = swatches[c].color;
rectRef.fillColor = rgbColor;
textRectRef = doc.pathItems.rectangle(y- t_v_pad,x+ t_h_pad, w-(2*t_h_pad),h-(2*t_v_pad));
textRef = doc.textFrames.areaText(textRectRef);
textRef.contents = swatches[c].name+ "\r" + getColorValues(swatches[c].color) ;
textRef.textRange.fillColor = is_dark(swatches[c].color)? white : black;
//
rectRef.move( swatchGroup, ElementPlacement.PLACEATBEGINNING );
textRef.move( swatchGroup, ElementPlacement.PLACEATBEGINNING );
swatchGroup.move( newGroup, ElementPlacement.PLACEATEND );
}
function getColorValues(color)
{
if(color.typename)
{
switch(color.typename)
{
case "CMYKColor":
if(displayAs == "CMYKColor"){
return ([Math.floor(color.cyan),Math.floor(color.magenta),Math.floor(color.yellow),Math.floor(co lor.black)]);}
else
{
color.typename="RGBColor";
return [Math.floor(color.red),Math.floor(color.green),Math.floor(color.blue)] ;
}
case "RGBColor":
if(displayAs == "CMYKColor"){
return rgb2cmyk(Math.floor(color.red),Math.floor(color.green),Math.floor(color.blue));
}else
{
return [Math.floor(color.red),Math.floor(color.green),Math.floor(color.blue)] ;
}
case "GrayColor":
if(displayAs == "CMYKColor"){
return rgb2cmyk(Math.floor(color.gray),Math.floor(color.gray),Math.floor(color.gray));
}else{
return [Math.floor(color.gray),Math.floor(color.gray),Math.floor(color.gray)];
}
case "SpotColor":
return getColorValues(color.spot.color);
}
}
return "Non Standard Color Type";
}
function rgb2cmyk (r,g,b) {
var computedC = 0;
var computedM = 0;
var computedY = 0;
var computedK = 0;
//remove spaces from input RGB values, convert to int
var r = parseInt( (''+r).replace(/\s/g,''),10 );
var g = parseInt( (''+g).replace(/\s/g,''),10 );
var b = parseInt( (''+b).replace(/\s/g,''),10 );
if ( r==null || g==null || b==null ||
isNaN(r) || isNaN(g)|| isNaN(b) )
{
alert ('Please enter numeric RGB values!');
return;
}
if (r<0 || g<0 || b<0 || r>255 || g>255 || b>255) {
alert ('RGB values must be in the range 0 to 255.');
return;
}
// BLACK
if (r==0 && g==0 && b==0) {
computedK = 1;
return [0,0,0,1];
}
computedC = 1 - (r/255);
computedM = 1 - (g/255);
computedY = 1 - (b/255);
var minCMY = Math.min(computedC,
Math.min(computedM,computedY));
computedC = (computedC - minCMY) / (1 - minCMY) ;
computedM = (computedM - minCMY) / (1 - minCMY) ;
computedY = (computedY - minCMY) / (1 - minCMY) ;
computedK = minCMY;
return [Math.floor(computedC*100),Math.floor(computedM*100),Math.floor(computedY*100),Math.floor (computedK*100)];
}
function is_dark(color){
if(color.typename)
{
switch(color.typename)
{
case "CMYKColor":
return (color.black>50 || (color.cyan>50 && color.magenta>50)) ? true : false;
case "RGBColor":
return (color.red<100 && color.green<100 ) ? true : false;
case "GrayColor":
return color.gray > 50 ? true : false;
case "SpotColor":
return is_dark(color.spot.color);
return false;
}
}
}
Find and Replace Script for multiple files
I am trying to find a script that will either open a selection of .ai files or run through all the open files in illustrator and complete a Find and Replace. Right now I have a script that runs the Find and Replace but I have to run it on each document instead of all my open files.
var openDocument = app.documents.item(0); var search_string = /001D/gi; // g for global search, remove i to make a case sensitive search var replace_string = '001E'; var text_frames = active_doc.textFrames; if (text_frames.length > 0) { for (var i = 0 ; i < text_frames.length; i++) { var this_text_frame = text_frames[i]; var new_string = this_text_frame.contents.replace(search_string, replace_string); if (new_string != this_text_frame.contents) { this_text_frame.contents = new_string; } } }
Thanks for any help.
Script: rename layers?
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
Retrieve whats in the clipboard possible?
Is it possible to retrieve whats in the clipboard through a script?
If so how?
CS4 - paste() produces: an illustrator error occurred: 2('')
I am automating copy and paste between two open files in Illustrator.I'm not using CreateFromFile since that strips variable names and otherwise alters the imported pageitems and makes them useless.
For some systems users get an error when the past command is used in the script.
Not much to it, after selected groups on the first document are selected a copy statement is used, the active document is changed, and a paste statement is used. It normally works but only on some combinations of selections on some computers. Adding a redraw() after the target document is activated avoids the error on some computers but not all.
copy(); doc.activate(); redraw(); doc.activeLayer = layerOption; paste();
An error occurs on the paste(); statement
an illustrator error occurred: 2('')
I've run directly from the ExtendScript toolkit editor and tried adding extra redraws() (to allow adobe to catch up to the scripting) all to no avail.
Any ideas on what I can try?
Setting the bleed in AI via Javascript
Hi All,
I'm writing a function to change the artboard size and add bleed depending on certain conditions.
I can't actually believe this is causing me trouble but here it is, I'm trying to set the bleed dimensions in AI document with Javascript. All I've found so far is setting up PDF export options or print options, but not the actual artboard Document Setup. I just want to be able to set bleed to a newly created document like in this window:
So similar to Indesign:
with(myDocument.documentPreferences){ documentBleedUniformSize = true; documentBleedTopOffset = 7; }
(CC2017)
How to add superscript 2 as text in textGroupItem with Javascript
Dear All,
I've been trying to add and remove certain pieces of text based on their font and whenever I need to add a certain piece of text back into it's original place again I need to insert a superscript 2 after this text.
This is the piece of code in which I add the text back in again:
if (textGroupItem.textRange.characterAttributes.textFont.toString().toLowerCase().match(regP attern)){
textGroupItem.textRange.characters.removeAll()
textGroupItem.textRange.characters.add(un + " - " + sm + "m" + "²")
}
This doens't give a superscript 2 but some kind of broken token as text.
So far i've also tried:
- translatePlaceholderText("c2b2")
- "2".sup()
- <sup> 2</sup>
- textGroupItem.textRange.characterAttributes.baselineShift = height; <-- height = 2 but this shifts the whole text item
How can you succesfully add a supercript 2 to a group of characters?