Select the layer name

I need to select a specific layer or group by name.  What is the correct syntax to do this with Javascript?

you want to select all the items on the layer? or only some types (e.g., blocks of text, groups, paths)?

Let's take a look at the same time.

Let's start by selecting all the elements on a given layer (in this case the layer is called "Target layer");

Note that pageItems means that any element of art in the document. could be text, could be a path, can be a group, could be a compound path.

var docRef = app.activeDocument;
var layers = docRef.layers;
var myLayer = layers["Target Layer"]; //this defines the layer that you want to get the selection from

docRef.selection = null; //ensure there is nothing in the document selected already. this way you only get the selection you want.
for(var a=0;a

now lets do the same thing, but we will choose just the groupItems

var docRef = app.activeDocument;
var layers = docRef.layers;
var myLayer = layers["Target Layer"];

docRef.selection = null;
for(var a=0;a

and finally, in order to be comprehensive, allows to select two different types of art objects, but not all types. For example, if a single layer has text blocks, groups, paths and transparent traces. Let's just select managers of related texts and groupItems. This time we will have to include a conditional statement to find the correct item types.

var docRef = app.activeDocument;
var layers = docRef.layers;
var myLayer = layers["Target Layer"];

docRef.selection = null;
for(var a=0;a 
         

Tags: Illustrator

Similar Questions

  • Select the layer function in action

    I have three layers with text in different languages. I want to record in three different PNG files.

    I tried to do action, select the layer, hide it and save it. Select another layer, then do the same thing. But the selection of layers is not saved to the action.

    Is there a solution?

    big thank you

    No, I don't think. The selections are what they mean - interactive decisions which provide a context for a tool or a command. What you would require a script, and even in this case, you have to take care to name the layers properly in the first place...

    Mylenium

  • JS CS4: Create the variable for the active layer, and then select the layer at the end of a script

    I'm come white with the verbiage and spin my wheels with OMV guide and script.

    var myOriginalLayer = app.activeDocument.layers.item (0);
    Alert (myOriginalLayer)

    Returns "layer object" and not the name of the layer.

    var myOriginalLayer = app.activeDocument.layers.lastItem () .name;

    Returns the name of the layer I want but not by choice.

    I am challenged on how to select the layer.

    Hi John,.

    The difference lies in that the [Object Layer] is the real object, and the 'name' is a property - like color.

    You can use one of these two approaches:

    var myOriginalLayer = app.activeDocument.layers.item (0);
    Alert (myOriginalLayer.Name);

    hosts the original layer object, and you can see the name if necessary :-)

    For re - select the layer, use

    app.activeDocument.activeLayer = myOriginalLayer;

    You can also select name goes like

    var myOriginalLayerNAME = app.activeDocument.layers.lastItem () .name;

    ...

    app.activeDocument.activeLayer = app.activeDocument.layers.item (myOriginalLayerNAME);

    I also noted the following:

    app.activeDocument.layers.item (0) points to the first layer of your document; not the 'active'. Similarly, app.activeDocument.layers.lastItem () points only to the very last. I don't know if the order of the activeDocument.layers array mimicks the order as shown in the tags palette, but I hope for it :-)

    To get/set the active layer, use app.activeDocument.activeLayer as shown above.

  • Select the column name when the value = something

    Is there a way to select the column name when there is a specific value in it?

    As follows:

    create table (abc123)

    COLUMN1 VARCHAR2 (50).

    COLUMN2 VARCHAR2 (50).

    Column3 varchar2 (50)

    );

    insert into abc123 values ('yes', 'Yes', 'No');

    insert into abc123 values ('no', 'Yes', 'No');

    INSERT INTO ABC123 VALUES ('no ',' no', 'No');

    insert into abc123 values ('yes', 'Yes', 'Yes');

    SELECT CASE WHEN COLUMN1 = 'Yes' THEN - the name of the column would be here somehow?

    WHEN COLUMN2 = 'Yes' THEN - the name of the column would be here somehow?

    WHERE Column3 = 'Yes' THEN - the name of the column would be here somehow?

    Another null

    finish as abc123 columnname

    final results for the just Column1 would be:

    COLUMN1

    NULL VALUE

    NULL VALUE

    COLUMN1

    I'm not sure what I use to get the name of column in there

    Thank you.

    Hello

    708631 wrote:

    Is there a way to select the column name when there is a specific value in it?

    As follows:

    create table (abc123)

    COLUMN1 VARCHAR2 (50).

    COLUMN2 VARCHAR2 (50).

    Column3 varchar2 (50)

    );

    insert into abc123 values ('yes', 'Yes', 'No');

    insert into abc123 values ('no', 'Yes', 'No');

    INSERT INTO ABC123 VALUES ('no ',' no', 'No');

    insert into abc123 values ('yes', 'Yes', 'Yes');

    SELECT CASE WHEN COLUMN1 = 'Yes' THEN - the name of the column would be here somehow?

    WHEN COLUMN2 = 'Yes' THEN - the name of the column would be here somehow?

    WHERE Column3 = 'Yes' THEN - the name of the column would be here somehow?

    Another null

    finish as abc123 columnname

    final results for the just Column1 would be:

    COLUMN1

    NULL VALUE

    NULL VALUE

    COLUMN1

    I'm not sure what I use to get the name of column in there

    Thank you.

    Thanks for posting the CREATE TABLE and INSERT for the sample data.

    Don't forget to post the exact results you want from these sample data.  If the results depend on the parameters you want to pass a run time, then give a few different examples, with the the desired results of each.

    You can hardcode the values you want, such as the column names in a query.  For example:

    SELECT CASE WHEN column1 = 'Yes' THEN 'Column1' END like y1

    CASE WHEN column2 = 'Yes' THEN 'Column2' END like y2

    CASE WHEN Column3 = 'Yes' THEN 'Column2' END like y3

    , a. *-If wanted

    Of abc123 one

    ;

  • How to use just 1 click away with the move (v command) tool to select the layer in the Group?

    I'm on Snow Leopard 10.6.8 Photoshop CS3 10.0.

    Is it possible to click only once with "V command" to select a layer in a group?

    I used to be able to do and on my laptop I can do now (same OS and Photoshop), but the mac that I use for my design work won't... I must also, right-click and select the layer highlighted. I have a document a lot of multilayer Photoshop with many groups, and it is an extra step of your time.

    Is there a preference I can turn on? Or some other simple typo?

    Thank you very much!

    Select the tool move and set the options of the control bar. By default, it took to select a group, simply change layer.

  • Select the computer name of the machine running a WebForm (10g)

    Hello. I am looking for a way to select the computer name of the machine running a Web (10 g) form. Is this possible?

    I know I want the Windows environment variable access is: % ComputerName %

    Any suggestions?

    There is a Win_API_Environment packeg in WEBUTIL with a function called Get_Computer_Name, this should do the job.

    Alternative (also using WEBUTIL, but without the dll call):

    CLIENT_HOST('cmd /c set COMPUTERNAME > c:\temp\computername.txt');
    

    Then use CLIENT_TEXTIO to read the contents of the file.

    Published by: Andreas Weiden on 14.01.2009 18:56

  • Select the schema name. How?

    Hi all

    Can be a very simple question, how can I select the scheme name that I am connected. I don't wear DBA privileges.


    -Sam
    SELECT USER FROM DUAL
    
  • I can't get rid of the layer names in the general properties tab layers PCB Ultiboard

    A bunch of DXF layer names have been concluded by Ultiboard 10.1 error a few years during a DXF for import operation. I have recently updated to 12.0 and hope that the old layers would be eliminated. I wanted to get rid of them for a long time. I tried to delete the file ub_config in AppData, but it didn't remove them. Is that all you can think to extract them from the clutches of the program? Thanks, Tod

    Hi Tod,

    I suspect one of your design files is the cause.  If you go to Options > CFP properties > general Layers, you see here DXF layers?  If you see the layers, you can select it and then press the delete button?

  • How to get the ID of the layer name layer?

    Hello everyone.

    Trouble with the implementation of a small script.

    I want to add to each of the selected layers in the Document a new layer with the image, make sure that the top of each layer.

    I think what I need:

    1. create a table of the layers selected by the user (necessarily by name)

    2. Select the image;

    3. pass by the table to create a layer, put in new picture selected layer and move the table above this layer.

    Found an example where the table is created on the index, but in my case it's not that - after that each addition of a new layer index is changes. How can I get the index of the layer by name?

    Andy_Bat1 wrote:

    But if I understand correctly, I need to know the ID or Index of the layer?

    No, you need a layer object (or layerSet). You can make reference to an object layer in several ways. The excerpt you posted has two, one is owned by activeLayer and the second is by index. You can also make a reference using the name of the layer and some methods like ArtLayers.add () return an object layer. The DOM is not an ID of the layer property.

    app.activeDocument.activeLayer.move (activeDocument.artLayers.getByName ('top'), ElementPlace ment. PLACEBEFORE);

    app.activeDocument.activeLayer.name = 'new top ";

  • The layer name must include

    Hello

    I'm trying to find the objects of magenta color applied. The code below works fine. But I need to write the name of layer error in the alert object.

    var pageLen = app.activeDocument.pages.length 
    var mag=0
    for(i=0;i<pageLen;i++)
    {
            var pageItemLen = app.activeDocument.pages.item(i).pageItems.length 
            for(j=0;j<pageItemLen;j++)
            { 
                color = 0; scolor =0
                if(app.activeDocument.pages.item(i).pageItems.item(j).fillColor.name != "None")
                    color = app.activeDocument.pages.item(i).pageItems.item(j).fillColor.colorValue
                if(app.activeDocument.pages.item(i).pageItems.item(j).strokeColor.name != "None")
                    scolor = app.activeDocument.pages.item(i).pageItems.item(j).strokeColor.colorValue
                if(color == "0,100,0,0" || scolor == "0,100,0,0")
                      mag=1
               }
        }
    
    
    if(mag==1)
    {
              alert("ERROR: Some Page ojects contain Magenta color fill/stroke")
        }
                    else{
                     alert("Page ojects not contain Magenta color fill/stroke")
    }
    

    I am bit confused how to add it. Please help me?

    Kind regards

    Kitty

    It is likely that your variable myLayer hosts only the last occurrence of layer name.

    You must store all possible values in a table.

    var pageLen = app.activeDocument.pages.length
    var mag=0;
    var myLayersArray = [];
    
    for(i=0;i		   
  • A Script to find and replace the layer names

    Is there scripts to find and replace the names of layers?

    There is an excellent script available for Photoshop that allows you not only to replace words in layer names, but also insert words as prefixes, Suffixes and sequential numbers.

    The version of the illustrator of this script allows only sequential numbering: it does not offer search and replace words.

    Ideally, it would be great if there were something that could find multiple and replaces in a go:

    (for example

    You have layers like this car, the dog, the bat

    You enter: because (Option1), dog (Option2), Bat (Option3)

    Your layers become then: option 1, option 2, Option3).

    )

    Big_SmiLe, which is a very good start! Step 1 of learning how to Script is indeed, by adjusting an existing simple script to make things more complicated. (And usually then "break something", which is also a necessary part of the process.)

    You are right your comment, it comes to repetitive things. For one or two different articles that wouldn't be a problem, but in the longer lists you are soon lost.

    As usual to work with lists of search - replace is to build a table:

    var layernames = [
    [ 'FHairBowlBoy *Hair', 'Hairboy1' ],
    [ 'FHairCurlyafroBoy *Hair', 'Hairboy2' ],
    [ 'FHairSpikyBoy *Hair', 'Hairboy3' ],
    ];
    

    The general idea is to loop through all the names, check if the current layer name is "layernames [i] [0]" (the left column) and if so, rename it "layernames [i] [1]" (the right column). If you know how to write a loop in Javascript, then you can implement this immediately.

    However...

    A more advanced method to do this didn't need even loop on all layernames - instead you can immediately 'get' the correct name by layer! It's magic! Almost!

    The trick is to use a Javascript object rather than a table. JavaScript objects are nothing special; "Layers" of Illustrator are an array of objects, and each object 'sex' has a 'name' property, which you can read and set the value. What I do here, is to create a new object, where the part 'name' is the name of the original layer and its value is the name of the new layer. All you need to check each layer is if there is a "object.originalLayerName" property and if so, assign its value to this layer name.

    It looks a bit like the table above, except that (1) you use {.} instead of [..] to create an object and (2) you add pairs "name: value" instead of 'value' only (in fact, the 'name' of a value in a table is simply her number).

    So here's 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!

  • I can't change the layer names

    Even if I double click on the names. The layers are not locked. I never had this problem in cs5.

    Hello!

    You should be able to just double click and rename your layer, as shown below.

    Since you said it does not work for you: with the layer is highlighted, go to layer > layer rename. This will allow you to rename your layer.

    Please post if you have any questions,

    Janelle Flores

  • Select the customer name in a menu drop-down select or be able to type in

    Hello

    Is there a way to allow my users to have an option to select a customer name in a menu drop-down select or be able to kick it...

    Thanks in advance

    Hello

    I don't know about build Apex point of AutoComplete.
    But if you use jQuery UI to create the AutoComplete for the text element, you must limit not list user see all values.

    Kind regards
    Jari

  • Impossible to select the layer.

    I make a film of typography. I am now at the part that I do a composition of each 5 layers. But after several times I'm stuck. Because as soon as I select a layer I select the publication I've done. It's just scared because I still get the error when I'm away in. Losing hours of work.

    If you never turned on, how ' end Open GL?  It should be off, too.  After these two easy to do things, you can dig deeper in the previous proposals if necessary.

  • Cannot select the layer via CTRL + ALT

    Hello

    If my memory is good, in CS3, I could ctrl + click on the layer alt while using the Brush tool. I can do is more in CS4. To do this, I first have to click on the selection tool, and then ctrl + alt click an image to select its corresponding layer, which is not a time saver. In any case, am I doing something wrong or avoid to activate certain features? Thanks in advance.

    Select the move tool and make sure automatic selection is checked and it is set to layer in the Options bar. To select another layer simply Ctrl + click on it in the document (no need to the ALT key). Is that what you want?

Maybe you are looking for

  • Skype wifi

    How much does the Skype wifi cost?

  • How do you turn antivirus program before playing games

    I tried everything to get the games to work.  How can I try to disable the antivirus program before you play my games? I get an Access Violation.  Thank you! Lana

  • Enable Java on my MSN homepage

    I can't change the home page to MSN weather because Java is not enabled. I looked everywhere to activate without success. Sounds pretty simple and I guess it is, but I'm not an expert computer user... Any advice will be welcomed. Thank you. Rob

  • Hard drive choppy. M17X R3 Ailenware

    Hi all For a year I have experienced rough hard drive. Usually noticed during playback of a video from the hard disk, it is also noticed when you mouse clicks, typing in word, etc. I downloaded a video of video playback. This video is streaming, howe

  • Removing applications for blackBerry Smartphones

    After you delete an app, why does remain the icon in the folder? Is anyway to remove this as well? Or should I just wait a while after it restarts until it disappears?