Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Recognizing all active/highlighted layers

Enthusiast ,
Nov 29, 2018 Nov 29, 2018

Hey guys, I've made an open source layer renaming utility and the repo is here:

InconsequentialPhonyCow-size_restricted.gif

One problem I have that I'm not sure how to solve yet is how to recognize that more than one layer is currently active/highlighted. Currently I'm only using the `activeLayer` property of the current document, and there doesn't seem to be any property within a Layer object for knowing that it's currently highlighted in the Layers panel. I'd like to be able to rename layers sequentially when more than one is selected, producing a list with numbers in a sequence as the suffix -- like highlighting 3 layers, and typing in "R Arm" to produce "R Arm1", "R Arm2", "R Arm3", etc. Renaming a single layer is pretty trivial, but is there any way or trick to find the indices of each currently selected layer and return them in an array? I did see an old post with qwertyfly giving a dynamic action but wasn't quite sure it was what I needed since it seemed to work with layer visibility alone.

TOPICS
Scripting
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Nov 29, 2018 Nov 29, 2018

action route might be your only option, if you decide to use it the workaround is to Hide or lock other layers, then go through all layers, check for visibility and do your thing. Then restore.

seems tedious but it works quite well

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 30, 2018 Nov 30, 2018

Thanks Carlos -- this might be a terminology problem on my end because I don't mean to add layers to app.selection, rather find which layers are highlighted inside the Layers panel. I'm not sure I follow because this isn't a static effect and I'm unsure what layers the user or myself would have highlighted at any given time, so I'm unable to use the lock specified layers route unless I'm misunderstanding or misspoke. I feel this is a bit of circular logic: in order to act on the layers I would need to lock all other layers, but locking all others implies I'd already know which layers I'm targeting or have highlighted to begin with, which is the end-goal rather than where I'd be starting.

In the above gif, I could highlight Layer 1, 2, and 3 -- or similarly 3, 4, and 5, or any combination of these. Is there no way or trick to directly query which are highlighted (not actively selected but highlighted)?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 30, 2018 Nov 30, 2018

Hi, as far as know, there's no way to query which layer is highlighted. Many of us have been looking for workarounds.

here's a step by step

0. deselect everything (optional)

1. highlight some layers in the layer panel

1.1 store layer visibility

2. go to the layer's menu and click on "Hide Others"

3. loop through all layers

4. is layer visible? do your thing

5. restore layer visibility

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 30, 2018 Nov 30, 2018

Hi Off Topic,

I thought of something that will not be very beautiful, maybe it might be useful, you can try the following:

First create a button that will call the script below as function and send the "String" with the new Layers name as the argument.

#target illustrator

#targetengine main

var dlgWin = new Window ('dialog', 'All Layers');

var stt = dlgWin.add ('statictext', undefined, 'Select Layers you want to Rename and click "Rename Button"')

var lstLayers = dlgWin.add ('listbox', undefined, '', {multiselect: true, numberOfColumns: 2, showHeaders: true, columnTitles: ["Index", "Layer Name"]});

lstLayers.preferredSize = [300, 200];

var btnRename = dlgWin.add ('button', undefined, 'Rename');

for (var i = 0; i < app.activeDocument.layers.length; i++){

 

    var lstItem = lstLayers.add ('item', i);

    lstItem.subItems[0].text = app.activeDocument.layers.name;

};

btnRename.onClick = function (){

    for (var i = 0; i < lstLayers.selection.length; i++){

        var layToReplace = lstLayers.selection;

        //Change "New name" to your edittext.text

        app.activeDocument.layers[layToReplace].name = "New Name_" + i;

    }; 

    dlgWin.close ();

};

dlgWin.show ();

I hope it help anyway.

Greetings

-Vinícius Dias

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 30, 2018 Nov 30, 2018

That's great, but OffTopic here already has a CEP extension and his goal is to make it as native-looking as possible. If you examine his gif movie, he already controls the layers panel via his own extension.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 30, 2018 Nov 30, 2018
LATEST

I think you may be somewhat ensnared by our usage of the 'dynamic' action procedure here, since a lot of the examples have to do with changing a variable in the action text to accomplish a task such as file-saving. In reality, the 'dynamic' more generally refers to something being written 'every time' we run some script or parent logic. The main purpose for this is to embed our actions inside scripts and not have to rely on users having the correct actions loaded inside their Actions panel which are necessary for script execution.

Although not ultra-short, the process of writing an action file, loading it into the actions panel and playing it and then removing it - all to get the targeted layers, is still nearly instantaneous. Otherwise just a simple app.doScript command will do if the user already has the action in the Actions panel loaded - an extra loose end from the scripter's perspective as these could be updated and mis-versioned among the clients workstations.

*Although in some cases you may want to put the ability to use the user-created actions as a special feature, that's a different whole category of objectives.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines