Replace layer names in selected layers only

I am using this script to find and replace words in layers. (The script only targets particualr words, rather than the whole layer name).
I would like to make it so it targets selected layers only.
I have found this script which loops through selected layers only, but I am not sure how to add the find and replace layer name functioality.
Thanks for any help that can be offered.

big_smile wrote:
Looking through the guide, it doesn't seem "hasSelectedArtwork", is a built in function either. Are there any tutorials or guides that explain how to target selected layers?
Wrong reference manual, see this one:
http://www.adobe.com/content/dam/Adobe/en/devnet/pdf/illustrator/scripting/cs6/Illustrator -Scripting-Reference-JavaScript.pdf
Page 91 -- CHAPTER 1: JavaScript Object Reference
Layer
Property
hasSelectedArtwork
Value type
boolean
What it is
If true, an object in this layer has been selected; set to false to deselect all objects in the layer.
So as I talked about here:
W_J_T wrote:
Correct. Yeah there is no direct way unfortunately (like many things via scripting), thats why I suggested using "hasSelectedArtwork", that would work if you select the layer target when selecting your desired layers to rename.
and...
W_J_T wrote:
if(layerReferenceString.hasSelectedArtwork == true){
     // relative code
That would offer a way to know if a layer is selected or not.
As far as I know that is the only round about way of knowing if a layer is selected via scripting.

Similar Messages

  • A Script to Find and Replace Layer Names

    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).

    big_smile, that's a very good start! Step 1 of Learning How To Script is indeed, adjusting an existing simple script to make it do more complicated things. (And usually then "break something", which is also a required part of the process.)
    You are correct in your observation this is repetitive stuff. For one or two different items that wouldn't be a problem, but in longer lists you soon get lost.
    The usual way of working with find-change lists is to build an array:
    var layernames = [
    [ 'FHairBowlBoy *Hair', 'Hairboy1' ],
    [ 'FHairCurlyafroBoy *Hair', 'Hairboy2' ],
    [ 'FHairSpikyBoy *Hair', 'Hairboy3' ],
    The general idea is to loop over all names, check if the current layer name is "layernames[i][0]" (the left column) and if so, rename it to "layernames[i][1]" (the right column). If you know how to write a loop in Javascript, then you can implement this right away.
    However ..
    A more advanced way to do this doesn't even need loop to over all layernames -- instead you can immediately "get" the correct name per layer! It's magic! Almost!
    The trick is to use a Javascript object instead of an array. Javascript objects are nothing special; Illustrator's 'layers' is an array of objects, and each object "layer" has a property "name", whose value you can read and set. What I do here is create a new object, where the "name" part is the original layer name and its value is the new layer name. All you need to check for per each layer is if there is a property 'object.originalLayerName', and if so, assign its value to that layer name.
    This looks a bit like the array above, except that (1) you use {..} instead of [..] to create an object, and (2) you add "name:value" pairs instead of "value" only (actually, the 'name' of a value in an array is simply its number).
    So this is what it looks like:
    // JavaScript Document
    var doc = app.activeDocument;
    // name indexed object
    var layernames = {
    'FHairBowlBoy *Hair':'Hairboy1',
    'FHairCurlyafroBoy *Hair':'Hairboy2',
    'FHairSpikyBoy *Hair':'Hairboy3'
    // loop through all layers
    for (var i = 0; i < doc.layers.length; i++)
    //Set up Variable to access layer name
    var currentLayer = app.activeDocument.layers[i];
    if (layernames[currentLayer.name])
      currentLayer.name = layernames[currentLayer.name];
    Enjoy!

  • Run action to find layer by name and select it...

    I have a folder of 10,000+ files that I need to run a simple action on. I'd like to open a file, have it find the topmost layer names "RED," select it, rasterize it, and then save/close. I've been able to figure out every step except selecting the layer I need. I've tried the "insert menu item" command in the actions drop down menu, but it only gives me options for things like "select all layers" or "select similar layers." The "Insert select path" only lets me select 10 paths at a time, and won't select compound paths. What I need is to be able to select a layer named "RED" as part of the action. Photoshop allows you to do that, so I was hoping Illustrator might afford me the same convenience. Any ideas?
    Vinny

    The following is an AppleScript. Open the ScriptEditor in the applescript folder and paste into a new window. Run it on a sample folder and we'll see how it does.
    --get a sourceFolder that holds the files to print
    set sourceFolder to (choose folder with prompt "Choose a folder with files to process:") as text
    -- get a list of files of the files to be printed in the sourceFolder
    tell application "Finder" to set workingFiles to (every file of folder sourceFolder) as alias list
    repeat with workingFile in workingFiles
        tell application "Adobe Illustrator"
            open workingFile
            tell current document
                set layerRef to (first layer whose name is "RED")
                set g to every page item of layerRef
                repeat with i from 1 to count of g
                    set selected of item i of g to true
                    do script "raster" from "Default Actions" without dialogs
                    delay 1
                end repeat
            end tell
            close current document with saving
        end tell
    end repeat
    Don't include the underlines.
    The do script line refers to an action you create in your default actions with just one thing. It's case sensitive.
    Let me know if you need more help

  • Command-clicking layer name does not load layer as a selection (Photoshop CS2)

    Q: Why does Cmd-clicking a layer name not load the layer as a selection in Photoshop CS2?
    A: You must Cmd-click the layer thumbnail, not the layer name, to load the the layer as a selection.
    In Photoshop CS2 Cmd-clicking the layer name in the Layers Palette selects the layer. To select multiple layers use the following keystrokes:
    1. Multiple contiguous layers = Shift+click layer name
    2. Multiple non-contiguous layers = Cmd+click layer name
    See also Adobe Knowledgebase
    Document 329005

    It works for me and doesn't seem to care what tool i have selected or anything like that to make a difference. Maybe you should reset your preferences as it may be a glitch.
    Hold Ctrl+Alt+Shift as soon as you tell photoshop to startup, and it will ask you if you want to delete the preferences, just click yes. (If you have a custom UI that you want to save, goto Windows>Workspace>Save Workspace, and then just reload it after resetting prefs.)

  • Ctrl-clicking layer name does not load layer opacity mask (CS2)

    Q: Ctrl-clicking a layer name does not load the layers opacity as a selection in CS2 as it did in older versions?
    A: You must ctrl-click the layer thumbnail, not the layer name, to select the opacity of the layer. Ctrl-clicking a layer name is now connected to the new way of selecting multiple layers in Photoshop CS2, as per the standard way of selecting multiple objects in the Win OS.

    Thanks for the replies:
    I tried the shift, ctrl & alt keys on start up of PS2 and received a msg fm windows Vista about the PS short cut. I said OK and nothing happened.
    I started PS2 and then held the shift, ctrl & alt keys while it was starting. This seemed to reset some things because the original message that comes with PS came up. But the mask problem is still there.
    I went further in your instructions and found the "reset all tools". Did that. Still have the problem with my mask not clearing totally.
    Any more suggestions???? Thanks, Al

  • How do I copy parts of layers from one AI doc into a new AI doc and keep/create same layer names?

    How do I copy PARTS of layers containing many objects from one CS5 AI (v.15.0.2) doc into a new CS5 AI doc and keep/create the same layer names?
    To start with, I have one fairly complex AI document with 100 layers,  with several hundred items in each layer. For example, one layer named "Stars" contains  400 separate stars (not grouped), another layer named "Crosses" contains 300 separate crosses, and a 3rd layer named "Text" contains 200 separate words (not outlined).
    If I select, by marqueeing a section of the image/artboard, some (but not all) of the individual items contained in the several layers, then  paste that selection into a new CS5 AI doc, I cannot get them to  create new layers of the same name. Instead they go into one general layer (e.g. "Layer 101") as a jumble of discrete, but unorganized objects (no layers or sublayers). In other words, I have lost the 3 main layers from which I selected a bunch of objects.
    Checking "Paste Remembers Layers" has no effect on this result. In fact "Paste Remembers Layers" does not remember layers at all. Only if I select ALL the items in the several layers will it paste those layers by those names into the new doc (or create new layers of the same names).
    Of course it is a COLOSSAL waste of time copying the ENTIRE document, then pasting the WHOLE thing into the new doc (with layers retained), then deleting the parts I DON'T need, so please don't suggest that as the solution.

    No Monica, nothing in Plug-ins other than the standard installed items (extensions, filters, formats, etc.). No 3rd-part clipboard extension on my computer that I'm aware of, either. All frustratingly basic. And my other CS5 Adobe programs appear to work well, at least to the extent that I am familiar with them.
    So, from what I can tell of the various comments (thanks to all of you), am I correct in thinking that it seems I can't, in fact, do what all of you can do (that is, copy some objects from some layers in one doc and paste into another doc preserving those same layers by name and organization, and each containing the correct objects from each original layer)?
    If so, that solves half my issue - "is it supposed to be possible to do it"; leaving just the other half - "why can't I do it too".
    I'll get those screenshots made and posted later just in case I haven't adequately described the issue, or y'all haven't understood it.

  • I can't get rid of layer names from the Ultiboard PCB properties-General layers tab

    A bunch of DXF layer names were erroneously entered into Ultiboard 10.1 a few years ago during a DXF importing operation. I upgraded to 12.0 recently and hoped that the old layers would be eliminated. I have been wanting to get rid of them for a long time. I tried deleting the ub_config file in AppData, but it didn't remove them. Is there anything you can think of to extract them from the program's grasp? Thanks, Tod
    Solved!
    Go to Solution.

    Hi Tod,
    I suspect one of your design file is causing this.  If you go to Options>>PCP Properties>>General Layers, do you see the DXF layers in here?  If you see the layers, can you select it then press the Delete button?
    Tien P.
    National Instruments

  • [CS3][JS] Selecting Layers by Name

    I'm trying to design a script to select layers by a given name. And then PDF layer1 (base) and certain items that are on each layer 1 at a time so I have multiple different pages. But the PDF thing doesn't seem to be much of an issue. I just can't select the layer by name.
    This is what I have so far:
    var myDocument = app.documents[0];
    var circusLayer = myDocument.layer[Circus];
    circusLayer.visible = false;
    Thanks!

    Hi Chris:
    var circusLayer = myDocument.layers.item("Circus");
    Thanks,
    Ole

  • Illustrator selecting layers by name then "make mask" command

    Hi guys,
    I'm trying to get a vbscript to do this maybe easy task for some of you
    I want to select 2 layers by name and then set the command :
    NameA = "nomdeCalqueA"
    NameB = "nomdeCalqueB"
    Set appRef = CreateObject("Illustrator.Application")
            Set idoc = appRef.ActiveDocument
            appRef.activeDocument.Selection = Empty
        For Each targetDocument In appRef.Documents
            countOfLayers = targetDocument.Layers.Count
            For layerIndex = countOfLayers To 1 Step -1
                Set targetLayer = targetDocument.Layers(layerIndex)
                    layerName = targetLayer.Name
                        If (InStr(layerName, NameA) = 1) Then
                        'then select my layer
                        End If
                        If (InStr(layerName, NameB) = 1) Then
                        'then select my layer
                        End If
    Next
    Next
            appRef.executeMenuCommand ("makeMask")
    I'm a little lost...
    Thank you for helping.
    Nems.

    iDoc.Layers("Name") in VB.NET ...  try it for VBS or possibly iDoc.Layers.Item("Name").
    Again -- just remember you're masking elements, not layers.
    Since you're more comfortable with VB maybe this could help, albeit it VB.NET. Translation should be pretty easy for you though. Note: I just pop in GUIDs to temporarily name the groups. You can use a different naming convention.
    Dim aDoc As Document = app.ActiveDocument
    aDoc.Selection = False
    Dim grp1 = CreateGroup(aDoc, "Layer 4")   'whatever layer name you want
    app.ExecuteMenuCommand("compoundPath")
    Dim grp2 = CreateGroup(aDoc, "Layer 2")   'whatever layer name you want
    app.ExecuteMenuCommand("makeMask")
    Private Function CreateGroup(aDoc As Document, layerName As String)
        Dim tmpGuid = Guid.NewGuid.ToString
        Dim layer As Layer = aDoc.Layers(layerName)
        Dim grp = layer.GroupItems.Add : grp.Name = tmpGuid
        For i = layer.PageItems.Count To 1 Step -1
            Dim pi = layer.PageItems(i)
            If Not pi.Name = tmpGuid Then pi.Move(layer.PageItems(tmpGuid), AiElementPlacement.aiPlaceInside)
        Next
        layer.PageItems(tmpGuid).Selected = True
        Return layer.PageItems(tmpGuid)
    End Function

  • Exporting Layers to PNG files using each layer name to create the file name??

    Hi All
    I'm trying to sort the following problem and was hoping somebody here could help with a scripting solution - my knowledge extends as far as actions unfortunately - which I don't think is appropriate for this.
    I've created a User interface in Illustrator with many layers and have exported this as a psd with layers.
    Basically what i'm wanting to do is export every layer as a png file while using the layer name to create the file name - each layer needs to be clipped.
    There is no transparency in the png.
    I've run the export to files script - but the names are too long and there is no anti aliasing.
    I've tried running a script from Illustrator - but it doesn't see sub layers - and doesn't name the layers.
    any help would be appreciated.
    thanking you in advance
    regards
    nate

    Hi,
    We just released this tool: FERRY (http://ferry.thedamarmada.com). It does exactly what you want and a little bit more.
    I think it's worth it a try.
    It comes with a free demo that will export 5 layers.
    Take a look and let us know if it's what you need.
    It could be easily tweaked.
    Jordi

  • How to identify selected layers in layer panel of Photoshop?

    Hi everyone,
    I'm working on a Photoshop plug-in, and I want to identify selected layers in layer panel.
    As I tested so far, didn't came up with a solution..
    If anyone can provide me a solution it will be greatly appreciated,
    Thanks in advanced..
    Nuwan.

    Looping through controls is indeed a inefficient way of doing what you want!
    With such a great number of controls, you could assign an appropriate callbackData to each of them when loading the panel. Next you could create an array of control IDs with all the LEDs and operate in the switch callback to turn on and off the corresponding led. A small example will be more clear:
    At panel load:
    int leds[200];
    SetCtrlAttribute (panelHandle, PANEL_SWITCH1, ATTR_CALLBACK_DATA, (void *)1); leds[1] = PANEL_LED1;
    SetCtrlAttribute (panelHandle, PANEL_SWITCH2, ATTR_CALLBACK_DATA, (void *)2); leds[2] = PANEL_LED2;
    SetCtrlAttribute (panelHandle, PANEL_SWITCH192, ATTR_CALLBACK_DATA, (void *)192); leds[192] = PANEL_LED192;
    In the switch callback:
    int CVICALLBACK switchOnOff (int panel, int control, int event,
    void *callbackData, int eventData1, int eventData2)
    int sts;
    if (event != EVENT_COMMIT) return 0;
    // Get the status of the switch
    GetCtrlVal (panel, control, &sts);
    // Set the led to the proper status
    SetCtrlVal (panel, leds[(int)callbackData], sts);
    return 0;
    For this solution to work, leds[] array must be global so that it is available to the control callback.
    An additional improvement could be to modify the panel loading so that swithces and leds are created programmatically. You could have a single switch/led pair set in the UIR editor and next have a loop that duplicate the controls, sets callbackData and loads the array of led ids.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • IDCS5: How to access selected layers in layer panel

    It seems the way to access the selected layers in layer panel has been changed in CS5.
    Here is a link to the code that worked with CS4, but it is not working on CS5.
    http://forums.adobe.com/message/1304622#1304622
    Is there some way to find out how it works in CS5?
    Thanks.

    Please check Panel Options > Thumbnail Size from the Layers Panel’s pop-up menu in the upper right corner.

  • Layer name / Layers Panel tool icons disappear

    The 'Template' checkbox gets activated in Layer Options dialog box, and the box gets closed, then, the Layer name and several icons at the bottom of the Layer Panel disappear.
    The Layer is still there without a name, and rolling over the icons on the Layers Panel I can see the Tool Icons.
    Illustrator Prefs were trashed/restored using the Opt-Shift-Command restart shortcut.
    Does anybody have any ideas?
    iMac 3.4 GHz Intel i7, 32 GB, OSX 10.8.2
    Illustrator CS6
    3rd party products
    Suitcase Fusion 4 ... 10.0.5 (515)
    Wacom Tablet Intuos 4... v6.3.5-3

    This happened to me out of the blue and after many hair pulling days, I figured out that if you set one of your layers to "not print" (by un-checking the print box in layer options) all of the text and icons disappear off every layer below that non-printing layer. So find the non-printing layer, click on it, go to the drop down menu at the top right of the layers palette, choose Options for layer, and check the "print" box. All of your layers should now look normal.
    I also read something about making sure the Verdana Italic font was active in your system fonts which mine was so that suggestion didn't help me. Good luck.

  • My iPhone 4S just replaced the names of my contacts in text messages and my favorites with only their phone numbers. Names are gone. The option to add new contacts also appears to be gone. I tried the *228 and it did not work. Help!

    My iPhone 4S has replaced the names of my contacts in text messages and under my favorites- only their phone number shows. I updated today but this actually happened beforehand. I have tried restating the phone, and also *228. Neither have worked. Can someone help me??

    My wife is having the same problems as a reciever. She works in a school as a teaching assistant and her teacher sends messages that are mixed with previous texts from ages ago.
    Can anyone shed some light on this problem or is it only her and this poster?
    2m42s

  • Script to search layer names

    Hi -
    Does anyone know if there is a script that can search through layer names within a file for a specific text string and then select it as the active layer?
    For instance, if a file has 4 layers, named My LayerX, LayerY, LayerZ, LayerA, I want to automatically search for a layer that has the text "rA" and make it the active layer.
    Thanks.

    This requires CS4 or better. It searchs using a RegExp and Action Manager so it should be very fast. It is set up now to deal with more than one matching layer.
    var re = /rA/;// a reg exp
    var matches = collectNamesAM(re);// get array of matching layer indexes
    for( var l = 0; l < matches.length; l++ ){
        makeActiveByIndex( l, false );
        // do something with layer
        alert(app.activeDocument.activeLayer.name);
    }// next match if any
    function collectNamesAM(re){
         var allLayers = new Array();
       var startLoop = Number( !hasBackground() );
       var endLoop = getNumberOfLayer();
       for( var l = startLoop;l < endLoop; l++){
            while( !isValidActiveLayer( l ) ) {
                l++;
            if( getLayerNameByIndex( l ).match(re) != null){
                allLayers.push( l );
         return allLayers;
    // Function: getActiveLayerIndex
    // Description: Gets gets the Action Manager API index
    //                        of activeLayer corrected for Background Layer
    // Usage: var idx = getActiveLayerIndex();
    // Input: None
    // Return: Number - correct AM itemIndex
    // Dependices: hasBackground
    function getActiveLayerIndex() {
         var ref = new ActionReference();
         ref.putProperty( 1349677170 , 1232366921 );
         ref.putEnumerated( 1283027488, 1332896878, 1416783732 );
         var res = executeActionGet(ref).getInteger( 1232366921 )
                                                           - Number( hasBackground() );
         res == 4 ? res++:res// why the skip in this doc?
         return res;  
    // Function: isValidActiveLayer( )
    // Description: Checks LayerSection for 'real' layers
    // Usage: if( isValidActiveLayer() )
    // Input: None
    // Return: Boolean - True if not the end of a Set
    // Notes:  Needed only if the layer was made active
    //               using Action Manager API
    function isValidActiveLayer( idx ) {
         var propName = stringIDToTypeID( 'layerSection' );// can't replace
         var ref = new ActionReference();
         ref.putProperty( 1349677170 , propName);// TypeID for "Prpr"
         // 'Lyr ", idx
         ref.putIndex( 1283027488, idx );
         var desc =  executeActionGet( ref );
         var type = desc.getEnumerationValue( propName );
         var res = typeIDToStringID( type );
         return res == 'layerSectionEnd' ? false:true;
    // Function: hasBackground
    // Description: Test for background layer using AM API
    // Usage: if( hasBackground() );
    // Input: None
    // Return: Boolean - true if doc has background layer
    // Notes:  Requires the document to be active
    //  DOM:  App.Document.backgroundLayer
    function hasBackground(){
        var res = undefined;
        try{
            var ref = new ActionReference();
            ref.putProperty( 1349677170 , 1315774496);
            ref.putIndex( 1283027488, 0 );
            executeActionGet(ref).getString(1315774496 );;
            res = true;
        }catch(e){ res = false}
        return res;
    function makeActiveByIndex( idx, forceVisible ){
         try{
              var desc = new ActionDescriptor();
              var ref = new ActionReference();
              ref.putIndex(charIDToTypeID( "Lyr " ), idx)
              desc.putReference( charIDToTypeID( "null" ), ref );
              desc.putBoolean( charIDToTypeID( "MkVs" ), forceVisible );
              executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
         }catch(e){ return -1;}
    function getNumberOfLayer(){
    var ref = new ActionReference();
    ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
    var desc = executeActionGet(ref);
    var numberOfLayer = desc.getInteger(charIDToTypeID("NmbL"));
    return numberOfLayer;
    function getLayerNameByIndex( idx ) {
        var ref = new ActionReference();
        ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "Nm  " ));
        ref.putIndex( charIDToTypeID( "Lyr " ), idx );
        return executeActionGet(ref).getString(charIDToTypeID( "Nm  " ));;

Maybe you are looking for