Illustrator Scripting :: Turn On Layer Visibility Without Exact Name?
Jan 4, 2013
I am realtively good with actionscript, so I am trying my hand at this to streamline our image exporting process. I am using CS5 on a PC.
We build our illustrator files to be a combination of different layers. Sometimes just one layer is exported at a time, and sometimes layers are combined to form a more complex image. We use layer names with instructions of what layers should be on and off.
An example of the layer naming might look like this:
03 (01-ON, 02-OFF)
02 (01-OFF)
01
I have been able to figure out how to check if there is a note to turn a layer on, my question is how do I select the layer to turn on the visibility without using the exact name of the layer?
In my example, when layer 3 gets exported, it should have layer "01" visible and layer "02 (01-OFF)" not visible. Since our files are always constructed differently (meaning 02 might not always have a note about 01 being off), I can't use the getByName option because I don't have an exact name to call the layer and turn the visibility on. The layers always start with 01, 02, 03, etc. Is there a way to use getByName and only have it look at the first 2 characters of the layer name?
Ive got like 300 layers, one of them being my main picture...this layer is all the way up in my list. When Im working on the bottom layers, I Have to scroll AAAAALLL the way up to turn on/off the visibility for that layer.. Is there a way to do this without scrolling up or down all the time?
I wanted to ask if by chance any of the scripting gurus here happen to have written an AI script that will take a number of selected sublayers/sub-sublayers and move them so they become top-level layers?
I am really needing this very badly, given that After Effects can only handle AI layers as separate entities. So I find myself moving tens, even hundreds of nested sublayers to the top level all the time.
I'm trying to write a script that renames a layer, and group within the layer, then an object within the layer (but not a part of the group) and have it run in a loop.
Here's what I've got so far, the group rename doesn't work.
#target Illustrator var doc = app.activeDocument; idLayers(doc)//IRename layers idGroups(doc)//Rename groups function idLayers(doc){
[code]....
I haven't put in anthing to rename the single object yet since I cant even get the group rename to work. I suspect that the group re-name section isn't working because I'm either using bad syntax or an invalid command.
How to toggle the layer lock/visibility in CS6 than in the earlier versions.
It seems that there's more padding around the lock/visibility icon, and you have to be really precise to click it... increasing the row size doesn't really make any difference, as the "padding" is still there. Wheres in the earlier versions clicking anywhere within the toggle box would enable/disable it.
Is it possible to script using a highlighted layer.
I know that selected items can be used for scripting, but I would like to just highlight the layers I want to process but not directly select the items on those layers.
I am working on a script to standardize layers and I need to move all the pageItems from a layer called "PART_NUMBER" to a layer named "STATIC".
following code at the arrow...
I am using "test" to troubleshoot the move.
standardizeLayerNames() // This function verifies that the Layer names conform to the standard Layer names. function standardizeLayerNames() { var myDoc7=app.activeDocument var myLayerCount7 = myDoc7.layers.length
I'm new in scripting and i need to make a script that moving all layers into a single layer (in Illustrator i press CTRL+A then CTRL+G in layers and works) but i need that in script.
It does almost what I need it to do. except that it also copies the ".ai" in to the layer name. Is there some way to modify this script to have it exclude or delete the file extension?
I am trying to iterate through objects in a layer and if the object satisfy a condition, I want to remove it.
Problem is that from what I suspect, if I use a "for loop" then when I remove an element, the initial length of the loop becomes invalid by removing the element. So what I would need is to iterate through objects in another matter and I am clueless.
I have a PDF file with 25 pages that I need to get into the form of an Illustrator file with 25 layers. I found the example of opening a particular page of a PDF file (using CS6), and that works. And I can create layers. But I can't figure out how to place a particular page of a PDF file into the new layer. Where/how do I provide the page info?
(I have a PostScript program that generates artwork for signs that are to be laser etched at the TechShop. The laser interface uses Illustrator and a special Print driver. I notice that opening a page from a PDF file positions the contents slightly differently than placing that page, when I do it manually, so I figured I'd create the multilayered Illustrator file by opening one page (which works) then placing all the pages in their own layers, then deleting the first page. Then the positioning will be consistent. But I'm stuck at placing a PDF page...)
tell application "Adobe Illustrator" to activate
-- This function opens the file passed as -- a file reference parameter, at page myPage. -- fileToOpen is a reference to a multi-page PDF file -- and needs to be set up before calling this function.
on openMultipageFile(fileToOpen, myPage) tell application "Adobe Illustrator" set user interaction level to never interact
I'm trying to build a map of the world that includes provinces and sub-provinces (counties). I will be animating it in AE. AE only sees the top layers so it is imparative that the name of the top layer corresponds the the correct province. Unfortunately all the provinces are not layers. They are objects. I can use the "Release to Layers" command to get all objects nested into top level layers. But the top level layers have generic names (Layer 1, Layer2, Layer 3). The objects nested within these layers have the correct name.
Is there a script that will rename the top level layer using the name given to the object nested within that layer? If not, how to create one?
Here's a link to one of the files: world_all_provinces_Senegal divisions. Level 1_area.zip
Are there any scripts to find and replace layer names?
There is an excellent script available for Photoshop which allows you to not only replace words in layer names, but also insert words as Prefixes, Suffixes and Sequential Numbers. The illustrator version of this script only allows sequential numbering: It doesn't offer find and replacing of words.
Ideally, it would be great if there was something that could do multiple find and replaces in one go:
(E.g. You have layers like this Car, Dog, Bat You enter: car(Option1), dog(Option2), Bat(Option3) Your layers then become: Option1, Option2, Option3). )
I recently created a script that reads the layer names of an Illustrator file, and uses the name to identify a swatch to use to pattern all elements on that specified layer. The script works well, and is a real time saver for our mapping staff, but it requires duplicate swatches to exist, where the only difference is their colour.
To improve the script I want to duplicate a swatch and modify its' colour before applying it to a specific layer. I think the only way this can be done is via the "placedItems" command. So the code I'm trying to write looks likke this:
for(var s=0; s<slib.length; s++){ // search swatch library var pat=slib[s].name; // get swatch name
[Code]...
However I'm struggling to find the correct syntax to make this work.
I'm looking to create a script to batch rename a number of artboards.
- I have 100 named layers.
- I have 100 artboards.
- I would like to rename the artboards to match the layer names.
- The layers are organized in the same descending orderas the artboards (ignoring the actual artboard names*).
- The topmost artboard (1 in the list) would be renamed "newspaper", the second artboard would be renamed "typewriter", the third artboard would be renamed "books", etc.
*in the example below the artboard named "Artboard 7" is actually the 6th artboard in list.
I have a script that measures the repeat interval and gap between print impressions printed using a print cylinder (for the production team to know which print cylinders to use, and what to expect once it prints, when looking at the proof sheet). Basically it just measures the distance from the beginning of one print impression to the beginning of the next (these are printed with a cylinder, so every time the cylinder rotates a new print impression happens) as well as the distance in between prints. That part works great.
In order to get these meaurements, Illustrator is measuring the distance from a zero point on the artboard to the left side of a marker I made called "repeat", and it is assigned a variable called rawRepeat. What I'd like to do is have the script take that rawRepeat value and use it to move a copy of the print impression to the right by exactly that variable amount and paste it beneath the marker called "repeat". I have been doing this part manually, but haven't been able to figure out how to get illustrator to do this for me.
Here's the script I am using:
var myDocument = app.activeDocument; var selectedObject = myDocument.selection; var activeLayer = app.activeDocument.activeLayer; var layerName = activeLayer.name; activeLayer.name = "plate";
I am trying to grab specific spot colors and move them to separate layers for our cutting software. In this case I am trying to grab "perimeter cut" and move it to a layer called "tc 1" I get the following error when I try to run the script.
#target Illustrator var idoc = app.activeDocument; var ipath = idoc.pathItems; if (ipath.typename == "SpotColor") { if (ipath.spot.name == "perimeter cut") { ipath.move(tc 1, ElementPlacement.PLACEATBEGINNING). } }
I have over 100 blocks that I need to add the exact same objects and visibility state to. Is there a way to globally make this change, or even to copy the visibility states from one block to the next without having to recreate the states in each block? I thought I had previously run across a routine on here that would make changes to multiple blocks at once, but I can't seem to find it now.
The Photoshop scripting guru Paul R over at RetouchPro has created a really cool script to batch rename and number selected Photoshop layers. I haven't found anything similar on the Illustrator side.
some Illustrator scripting genius could come up with a similar script for Illustrator. Would it be terribly difficult to convert this into something Illustrator could use? URL....
I think I might be doing this wrong, I am trying to get contents of a specific textFrame within first group on layer called "page numbers"
It seems to work, but is a bit sketchy, the documentation indicates textFrame is all the text frames in a document, and that textFrameItem should be the specific one within collections of groups etc, maybe I am misunderstanding. this is what I am using:
var existingPageNumbers = app.activeDocument.layers.getByName('page numbers').groupItems[0].textFrames[0].contents;