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

AppleScript moving certain colours to new layers

$
0
0

Hi all. This is my first question here. I'm attempting to use AppleScript to organize the layers of my art files.

 

What I am looking to do is have all objects with a fill color that is a specific CMYK value moved to a new layer. I don't know enough about how AppleScript and Illustrator's scripting interface works to make this function.

 

In my mind, I want to write something like this:

select all objects with fill color CMYK:100,80,0,0

move selection to Layer 2

 

AppleScripts always seem to be far more complicated than I initially envision them. Any thoughts on how this might actually be written?

 

Thanks so much.

David


Create a Duplicate Gradient Swatch

$
0
0

Hey Again,

 

I'm trying to challenge myself here, I want to create a copy of every gradient in the active document and give it an assigned name like "Batman 1" "Batman 2" ect.

 

I can add new gradients and set their stop colors ect but I can't figure out how to create a perfect copy of the gradient in the swatch library.

 

Does any know if this is even possible?

 

I've been looking and the only thing I found that comes close was an older script that's only compatibale with CS. In this they're copying EVERYTHING I just wanna stick to gradients at the moment. Here's the link: http://illustrator.hilfdirselbst.ch/dokuwiki/en/skripte/javascript/wr-usedcolors

 

I looked to this as an example of how to do something like this but since it wont work with CS6 I cant really experiment or tinker to figure out how it works.

How to select the outermost pathPoints in Compound or Grouped pathItems?

$
0
0

Hello Hiroyuki, Carlos and AISComm.,

 

i have an number of paths in a group each filled with single colors.

3) I hoped there is a way to select the outermost pathPoints on the perimeter of the group?

 

The following script i just found by wysiwygbill at: http://forums.adobe.com/message/3046178#3046178  ..,he writes: "..it's supposed to return the outermost bounds of the group". So it may save time in adapting it to select the points at the outermost bounds.

Please let me know if this is helpful and can be done?

 

Thanks as always, for your valued help and effective coding,

Jeff

 

 

function getRealVisibleBounds(grp) {

     var outerBounds = [];

     for(var i = grp.pageItems.length - 1; i >= 0;i--)  {

          var bounds = [];

          if(grp.pageItems[i].typename == 'GroupItem') {

               bounds =  getRealVisibleBounds(grp.pageItems[i]);

          }

          else if((grp.pageItems[i].typename == 'PathItem' || grp.pageItems[i].typename == 'CompoundPathItem')

               && (grp.pageItems[i].clipping || !grp.clipped)) {

               bounds = grp.pageItems[i].visibleBounds;

          }

          if (bounds.length > 0) {

               outerBounds = maxBounds(outerBounds,bounds);

          }

     }

     return (outerBounds.length == 0) ? null : outerBounds;

}

 

function maxBounds(ary1,ary2) {

     var res = [];

     if(ary1.length == 0)

          res = ary2;

     else if(ary2.length == 0)

          res = ary1;

     else {

          res[0] = Math.min(ary1[0],ary2[0]);

          res[1] = Math.max(ary1[1],ary2[1]);

          res[2] = Math.max(ary1[2],ary2[2]);

          res[3] = Math.min(ary1[3],ary2[3]);

     }

     return res;

}

 

function positionVisible(grp,x,y)

{

     var bounds = getRealVisibleBounds(grp);

     var newX = x + (grp.left - bounds[0]);

     var newY = y + (grp.top - bounds[1]);

     grp.position = [newX,newY];

}

Shortcut for js script with CS4 ?

$
0
0

hi all,

with my old version of illustrator (CS), i might affect a shortcut to a specific scipt .

Now i have CS4 version, and i  don't find similar possibility.

 

how can affect in this new version ?

 

Thanks for futur answer.

All Group to Ungroup Script

Acrobat

$
0
0

Hello everyone, I currently use the option to "preflight" the acrobat to check for errors in the files, you can make a script that opens a file. Ai in Acrobat and use the "preflight" I have set up to test the file, if possible could someone give me a starting point?

 

 

Thank you

Script UI breaks connection with AI Document?

$
0
0

Last week I wrote a simple script that interacts with my document and exports layers as images.

 

The script works great, but I thought I'd add a nice UI to it before I release it to the world, so I spent last Saturday making the GUI.

 

Now, I've built my UI, and I hook it up to my existing code.

 

If I  trace the current "activeDocument" at the beginning of my code, before I instantiate the window, I get what you would expect:

 

alert("Current Window:"+.app.activeDocument);//  Traces -   Current Window:[Document myTestDoc.ai]

 

Now if I try to reference my document from the window click handler, or after I've closed my window I get this:

 

alert("Current Window:"+.app.activeDocument);//  Traces -       Current Window:[Document]

alert("Current Window:"+.app.documents[0]);//  Also Traces -   Current Window:[Document]

 

The script can still see the document, but suddenly it can't introspect it.

"app.documents" yields the correct number of open documents,

"app.name" yields the correct application "Adobe Illustrator"

 

but anything like the following will fail.

 

alert(app.documents[0].layers.length);

 

Any advice would be massively appreciated.

 

thanks,

-J

Way to get rid of script alert when running script by double clicking?

$
0
0

Is there a way to disable to "You are about to run a script..." alert that pops up when running a scrip from windows explorer via double click?


script UI onClick listener not reading selection correctly

$
0
0

for some reason when I call the event listener on a button it doesn't want to store the selection  (might be losing selection onBlur? not sure)

 

there are several lines that really confuse me, because of scope, they should have access to the selection since it is defined outside the function. Here is a gist of the code since I cant stand forums syntax highlighting :X

 

https://gist.github.com/3030813

 

line 43-50 are where I am the most confused. any ideas?

Executing VBS from SQL Server Stored Procedure

$
0
0

The VBS script works outside of SQL server but not when executed from within a SQL Server Stored Procedure using this code:      

SET @VBSCommandLine ='cscript.exe C:\PrintLabels\TestVBS.vbs //H:CScript //Nologo'

 

 

 

 

 

 

EXEC master..xp_cmdshell @VBSCommandLine

 

The VBS code dies when it gets to the appRef.Open("C:\PrintLabels\PLT.ait") statement saying the the server has thrown an exception.

The VBS Script File

'PrintLabel.vbs
'This script opens an ai template, plays some actions to import two images, prints the file,
' and quits ai without saving the file
'
Wscript.echo("Before Illustrator")
Set appRef = CreateObject("Illustrator.Application.CS5.1")
Set fileSystemObject = CreateObject("Scripting.FileSystemObject")

'Suppresses user input
appRef.UserInteractionLevel = -1

' Open input doc
appRef.Open("C:\PrintLabels\PLT.ait")
Set docRef = appRef.ActiveDocument
inputFileName = docRef.Name
Wscript.echo("Before Place files")

'Places the files
set sDirName = "C:\PrintLabels\PSDFiles"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder("C:\PrintLabels\PSDFiles")
Set fls = fldr.Files

Dim fileNames(2)
i = 1
num = 0
Dim aFile
        For each aFile in fls
  ' Ignore system files. 
  If not aFile.attributes and 4 Then  
   num = num + 1
             fileNames(num) = CStr(aFile) 
  End If
        Next

dim imageLeft
dim imageTop
dim imageSize

' Place the first image
imageLeft = 18
imageTop = -423
imageSize = 5.0

Call AddRasterItemToPage(docRef, fileNames(1), imageLeft, imageTop, (imageSize) )

 

' Place the second image
imageLeft = 18
imageTop = -31
imageSize = 5.0

Call AddRasterItemToPage(docRef, fileNames(2), imageLeft, imageTop, (imageSize) )

myOutputFile = "C:\PrintLabels\TempAIFile\TempLabelAutoTest.ai"
docRef.SaveAS (myOutputFile)
Wscript.echo("After save file")

Set jobOptionsRef = CreateObject("Illustrator.PrintJobOptions")
Set printOpts = CreateObject("Illustrator.printOptions")


jobOptionsRef.Designation = 0 'aiVisiblePrintableLayers
jobOptionsRef.Copies = 1
printOpts.JobOptions = jobOptionsRef
printOpts.PrinterName = "OCIO-CapGal-4071A-1"
printOpts.PrintPreset = "3/4 Sticker Print"
Wscript.echo("Before print")
docRef.PrintOut printOpts

docRef.Close()
Set docRef = Nothing
Wscript.echo("just before exit")

'Exits Adobe Illustrator

appRef.Quit

Wscript.echo("just after exit")

' This routine adds all images in the folder as RasterItems
' to the Document

Sub AddRasterItemToPage(aDocument, theFile, imageLeft, imageTop, imageSize)
       
        ' Create a new raster item and link it to the image file
        Set aPlacedItem = aDocument.PlacedItems.Add
    aPlacedItem.File = theFile
       
       
        ' Move the raster item
        aPlacedItem.Position = Array(imageLeft,imageTop)
       
        Exit Sub

End Sub

 

[JS] CS6+ executeMenuCommand

$
0
0

Hello together,

 

since CS6+ there is possible to

executeMenuCommand (menuCommandString: string)

Executes a menu command using the menu shortcut string.

 

Question 1:

Who knows a way to read all the available commands?

 

Question 2:

At the time I need 'Clear Guides'

 

app.executeMenuCommand ('Clear Guides')

app.executeMenuCommand ('Clear guides')

app.executeMenuCommand ('clear Guides')

app.executeMenuCommand ('ClearGuides')

app.executeMenuCommand ('clear guides')

 

and other variants doesn't work.

 

Who know the right syntax? (Or is this menu command not available????)

 

 

Any help is appreciated. (Additional: I know the way to use app.doScript (myAction) - but this is not part of my questions)

Batch replace color without using swatch as source

$
0
0

I've searched these forums and the rest of the web trying to find a method to do this... Actions don't cut it (if Actions were able to record the "replace color" dialoge it would be fine) so I've turned to scripts, but I have almost no knowlege on this.

 

I checked out this thread:

http://forums.adobe.com/message/2588737

 

and it is very close, except that it assumes that there is a named swatch as the source color - which there isn't.

 

The script I tried was .JS

 

I'm trying to have the script run on a bunch of .eps files in a folder:

- Select object which has specified CMYK value (0,7,34,10)

- Replace fill color of the selected object with another CMYK value (5,19,36,0)

- Save over the existing .eps

- Close

- Make coffee (optional)

 

Also, any books you can recommend for learning this stuff? For a noob.

JS - Center Selection to Artboard / New Document with certain Artboard size

$
0
0

TL;DR:

how do I center my current selection to the artboard?

just like hitting the "horizontal align-center" and "vertical align-center" buttons.

 

 

Hi,

 

I've been searching for the last two hours and before my head hits the keyboard I wanted to ask you for help.

 

What I'm struggling with:

in my init function i create a new document and then copy all layers from the previous document step by step to the new document and then save it as SVG.

 

// Init

(function(){

          destination = Folder.selectDialog('Select folder for SVG files.', docPath);

          if (!destination){return;}

          holderDoc = app.documents.add();

          stepThroughAndExportLayers(docRef.layers);

}());

 

my problem is that holderDoc = app.documents.add(); always creates a document that is not the same size as my initial document where the layers get copied from.

 

so I want the exact same artboard size as in my initial document.

I'm fine with either doing it as fixed values or taking directly the values of the inital doc.

 

i tried this in the segment where I create the new document:

 

// Init

(function(){

  destination = Folder.selectDialog('Select folder for SVG files.', docPath);

  if (!destination){return;}

  holderDoc = app.documents.add();

  holderDoc.artboards[0].artboardRect = [0,0,128,128];

  stepThroughAndExportLayers(docRef.layers);

}());

 

and get this error message:

"Error 1200: an Illustrator error occured: 1346458189 ('PARM')

Line: 83

-> holderDoc.artboards[0].artboardRect = [0,0,128,128];"

 

which from what I've read on the web means that illustrator doesnt know what document to pick. but i have called it directly. so what could be the issue?

 

to clearify: I do not want to fit the artboard to the images/layer. the artboard should always have a certain size. (for me 128px by 128px)

 

I would highly appreciate you helping me with either fixing my approach or propose a completely new one.

Thanks so much in advance.

 

// edit: workaround


(function(){

          destination = Folder.selectDialog('Select folder for SVG files.', docPath);

          if (!destination){return;}

          var activeArtboard = app.activeDocument.artboards[app.activeDocument.artboards.getActiveArtboardIndex()];

          var ABRect = activeArtboard.artboardRect;

          holderDoc = app.documents.add();

          holderDoc.artboards.add(ABRect);

          holderDoc.artboards.remove(0);

          holderDoc.artboards.setActiveArtboardIndex(0);

          //stepThroughAndExportLayers(docRef.layers);

}());

 

i now added a new artboard to the new document with the same size as the artboard on the initial document.

i remove the predefined artboard on the new doc and set the new artboard as active.

BUT!

the artboard is now not centered into the window. which lets illustrator place my image with ctrl+c -> ctrl+v somewhere outside the artboard.

 

i now need to align my selection to the center of the artboard. but i cant find any reference on how to center a selection to the artboard.

Select an object in illustrator using extendscript

$
0
0

I have a drawn rectangle on an illustrator document. In the layers menu I have given it a specific path name (outerBox). I would like to select this item and return its particular properties eg height, width, colour etc. How would I do this.

 

Thanks

Bob

How to select multiple pathPoints?

$
0
0

Hello,

         i'm getting conflicting answers for wether its possible to select pathPoints at all, but could anyone please describe how to select multiple pathPoints?, if its possible.

 

I've had some success by writing a simple script that accesses pathPoints then aligns them with the manually chosen, highest point (highest Y value):

 

var firstPath = app.activeDocument.pathItems[1];                                    

var countOfPoints = firstPath.pathPoints.length;

var index               = 0;                                                                                  

 

for(index=0; index<=countOfPoints; index++)

{

var currentPoint        = firstPath.pathPoints[index];                                               

currentAnchorList     = currentPoint.anchor;

TopY                         = app.activeDocument.pathItems[1].pathPoints[0].anchor[1];

currentPoint.anchor = Array(currentAnchorList[0],TopY);                                   

}

 

...it works but is not finished.

It shows however that existing pathPoints can be edited/manipulated in almost every way, except there does NOT appear to be any way to perform the simpler task of selecting pathPoints or anchor points?

 

The closest i've found is: ..pathItems.selected = true;  ..but this does Not work when applied to pathPoints\Anchors, IE:

 

app.activeDocument.pathItems[1].pathPoints[index].anchor.selected = true;   ..AND,..

app.activeDocument.pathItems[1].pathPoints[index].selected = true;

 

...both fail to select any points.

 

1) please reply if you know how to select pathPoints and\or anchor points?, and\or have any alternative suggestions\instructions.

thanks much for any assistance,.

J


Getting 1346458189 ('PARM') error

$
0
0

From the readme:

"An Illustrator error occurred: 1346458189 ('PARM')" alert (1459349)    Affects: JavaScript    Problem:     This alert may be popped when badly written scripts are repeatedly      run in Illustrator from the ExtendScript Toolkit      Scripters need to be very careful about variable initialization and      namespace conflict when repeatedly pushing a batch of Illustrator scripts     for execution in Illustrator via the ExtendScript Toolkit (ESTK) in a      single Illustrator session. Each script run is executed within the same      persistent ExtendScript engine within Illustrator. The ESTK debugger      uses BridgeTalk to communicate with Illustrator. One global, persistent      ExtendScript engine inside Illustrator handles all BridgeTalk      communications. The net effect is that the state of the ExtendScript      engine is cumulative across all scripts that ran previously.      The following issues with script code can cause this problem:        - Reading uninitialized variables.        - Global namespace conflicts, like when two globals from different         scripts clobber each other.    Workaround:     Initialize variables before using them, and consider the scope of      your variables carefully. For example, isolate your variables by      wrapping them within systematically named functions. Instead of:             var myDoc = app.documents.add();       // Add code to process myDoc           Wrap myDoc in a function that follows a systematic naming scheme:             function myFeatureNameProcessDoc() {      var myDoc = app.documents.add();      // Add code to process myDoc      }      myFeatureNameProcessDoc();

 

 

This makes zero sense to me. If javascript variables are being reused or 'clobbered' or your javascript is 'poorly written' (this is not defined) it should have no effect on the scripting engine. Errors should cause exceptions to be thrown, which can be caught by the script.  I'm getting these errors when I try to evaluate properties of valid objects, for instance trying to access pathItem.fillColor. It's happening in various (almost random) lines in my script. Javascript doesn't have namespaces so I don't know what a 'namespace confilct' would be. Accessing variables from nested functions also seems to be a problem.

 

Edit - this seems to be related to accessing global variables or variables defined in containing functions. For now, adding var to the first use in subfunction seems to have fixed the problem. What is strange is you don't get an undefined variable error, it just crashes when it tries to access the properties.

 

Edit - still not fixed. I'm guessing it has something to do with memory allocation, because I am processing a lot of big raster images in todays batch of files.

 

Edit - processed 84 files today with no errors the pattern I'm using is to use a bach file that loops

 

"(Path)/Extend Script Toolkit.exe" -run script

sleep 10

 

The script opens a group of files (in my case JSON files), processes one file, exports an ai file, deletes the JSON file, then exits.

How to make button Illustrator script ?

$
0
0

Dear All,

 

Recently, I alway use free 2 Illustrator script text are: "joinTextFrames" & "divideTextFrame"

but I lost many step to do it

 

for example click: 1. select text -> 2. File -> 3. Script -> 4. Other script -> load script

Faster way -> Ctrl + F12  -> load script

 

But now I want make it to be 2 button "joinTextFrames" & "divideTextFrame". The same way "button mode" in actions for fastest work.

 

How to do it or solution to make it? I really need it for my work.

 

Thanks you for your help.

XMP - Add keywords with script

$
0
0

Hallo Forum,

 

I would create a script to have keyword standards.

 

In EXCEL i create a controlled namespace trougth comboboxes to save the files in an controlled way. The Metadata should be a controlled way to avoid "phantasie"-names. Having this values I would insert this strings in the XMP:KEYWORD field. In this way with the bridge I can retrive the information.

 

xmp.string = word1, word2, word3, ...

 

I use VBA and at the moment I have this but it doesn't work.

 

Sub meta_add ()

dim w1 as string

w1 = "hallo world"

document.xmpString.add.w1

end sub

 

Somebody can help me with the basic? JAVA would be welcomed too !!!

Thank you

Form.JPG

SVG-files into one layered AI-file

$
0
0

Hello good guys!

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

 

- Kenn

artboard coordinate

$
0
0

Hi,

 

I'm a newbie concerning scripting and i need your help.

 

Here is the situation : In Illustrator CS6, I have one artboard, and a second one, which has the same size than the first. The right side of one is on the left side of the other. Then we can export two .eps files to publish books.

 

Now, I would like to resize the first artboard as the new size becomes (artboard 0 + artboard 1) by writing a script (because there are a lot of files to work on). Or eventually create a third artboard, whose size is still (artboard0 + artboard1).

 

The problem is that every file has different artboards : the height can change but the horizontal size stays the same.

 

Here is my opinion, and 3 alternatives.

     -We should write a script which makes the first artboard (artboard 0) twice bigger only to the right side.

     -I can't be sure that "artboard 0" is always the one on the left (even if it should be like this), so the best way is to merge both of the artboards, but Im not sure it's possible by scripting.

     -Create a third artboard, whose coordonates are the same on left corners of left artboard, end the same on right corners of right artboard.

 

I hope I've been clear, and that you can help me on that.

 

Thank you all in advance !

Viewing all 12845 articles
Browse latest View live


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