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

Select only highlighted layers?

Engaged ,
Dec 20, 2015 Dec 20, 2015

Copy link to clipboard

Copied

Is there any way to get at only highlighted layers?

For example, I want to get an array/object that contains only the layers highlighted in blue:

Screenshot 2015-12-20 21.40.27.png

I'd prefer to not select the artwork in order to do this.

Thanks!

M

TOPICS
Scripting

Views

2.0K

Translate

Translate

Report

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

correct answers 1 Correct answer

Guide , Dec 21, 2015 Dec 21, 2015

Give this a shot.

it will leave you with an array containing the layers that you had selected in the layers panel when the script is run.

you can see down the bottom I loop this array so you can see each ones name and original visibility

function get_selected_layers(){

    var doc = app.activeDocument;

    var lays = doc.layers;

    var OriginalLayers = [];

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

        OriginalLayers.push(lays.visible);

        if(!lays.visible){

            lays.visible = tru

...

Votes

Translate

Translate
Adobe
Community Expert ,
Dec 21, 2015 Dec 21, 2015

Copy link to clipboard

Copied

record an Action to Hide or Lock Other Layers, play such action, then loop thru all layers and do your thing on the ones that are not locked or hidden.

you can incorporate the action creation in your script if you need to distribute it to others.

Votes

Translate

Translate

Report

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
Guide ,
Dec 21, 2015 Dec 21, 2015

Copy link to clipboard

Copied

Hi..

If image is the main problem..then you can get the layer objects..if a layer has images then you ignore that.. simple

var myDoc = app.activeDocument; 

    for(var i = 0; i < myDoc.layers.length; i++) 

    {    

        if(myDoc.layers.allGraphics.length!=0)

        {

            alert(myDoc.layers.name)

            }

     }  

Votes

Translate

Translate

Report

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 ,
Dec 21, 2015 Dec 21, 2015

Copy link to clipboard

Copied

Isn't "allGraphics" from InDesign scripting?

Votes

Translate

Translate

Report

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 ,
Dec 21, 2015 Dec 21, 2015

Copy link to clipboard

Copied

Hi Micky,

Please somebody correct me if I'm wrong, I think is not possible because layers is not a object with selection properties, but you can find other ways to manipulate the layers like locked, visible, selected pageItems, selected placedItems, selected rasterItems or whatever others particularities in your layers, depending of the purpose you need.

I hope you will be able to solve your problem.

Best regards

-Vinicius

Votes

Translate

Translate

Report

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
Guide ,
Dec 21, 2015 Dec 21, 2015

Copy link to clipboard

Copied

Give this a shot.

it will leave you with an array containing the layers that you had selected in the layers panel when the script is run.

you can see down the bottom I loop this array so you can see each ones name and original visibility

function get_selected_layers(){

    var doc = app.activeDocument;

    var lays = doc.layers;

    var OriginalLayers = [];

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

        OriginalLayers.push(lays.visible);

        if(!lays.visible){

            lays.visible = true;

        }

    }

    make_action();

    var SelectedLayers = [];

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

        if(lays.visible){

            SelectedLayers.push(lays);

        }

    }

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

            lays.visible = OriginalLayers;

    }

    return SelectedLayers;

    function make_action(){

        // Set you action name and the set name that it belongs to here

        var myAction = "Select_Layers";

        var mySet = "Scripted_Actions";

        //---------------------------------------------------------------------------------

        var currentInteractionLevel = app.userInteractionLevel;

        app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

        var actionStr = [

            '/version 3',

            '/name [ 16',

            '53637269707465645f416374696f6e73',

            ']',

            '/isOpen 0',

            '/actionCount 1',

            '/action-1 {',

            '/name [ 13',

            '53656c6563745f4c6179657273',

            ']',

            '/keyIndex 0',

            '/colorIndex 0',

            '/isOpen 0',

            '/eventCount 1',

            '/event-1 {',

            '/useRulersIn1stQuadrant 0',

            '/internalName (ai_plugin_Layer)',

            '/localizedName [ 5',

            '4c61796572',

            ']',

            '/isOpen 0',

            '/isOn 1',

            '/hasDialog 0',

            '/parameterCount 3',

            '/parameter-1 {',

            '/key 1836411236',

            '/showInPalette -1',

            '/type (integer)',

            '/value 7',

            '}',

            '/parameter-2 {',

            '/key 1937008996',

            '/showInPalette -1',

            '/type (integer)',

            '/value 23',

            '}',

            '/parameter-3 {',

            '/key 1851878757',

            '/showInPalette -1',

            '/type (ustring)',

            '/value [ 11',

            '48696465204f7468657273',

            ']',

            '}',

            '}',

            '}'

        ].join('\n');

        createAction(actionStr); 

        app.doScript(myAction, mySet, false);

        actionStr = null;

        app.unloadAction(mySet,"");

        app.userInteractionLevel = currentInteractionLevel;

    }

    function createAction (str) { 

        var f = new File('~/ScriptAction.aia'); 

        f.open('w'); 

        f.write(str); 

        f.close(); 

        app.loadAction(f); 

        f.remove(); 

    }

}

var myLayers = get_selected_layers();

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

    alert(myLayers.name + ", " + myLayers.visible);

}

Votes

Translate

Translate

Report

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 ,
Dec 22, 2015 Dec 22, 2015

Copy link to clipboard

Copied

Hey Qwertyfly...‌ you are incredible man hahahah..... Your solution is wonderful, working like a charm, I love the way you have found send to array the original visibility of layers, and use a action to identify the selected layers, congratulations, thank you for one more time helped us.

Votes

Translate

Translate

Report

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
Guide ,
Dec 22, 2015 Dec 22, 2015

Copy link to clipboard

Copied

‌this one was fun.

tthere were a number of things I had to try before I settled on the visibility property.

THis is was the cleanest solution I could come up with.

Hope it helps out a few people.

Votes

Translate

Translate

Report

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
Engaged ,
Dec 24, 2015 Dec 24, 2015

Copy link to clipboard

Copied

Also, what doe the action actually do? I hate to sound ignorant, but I don't understand what exactly it does by just looking at the code.

What are the action parameters for?

I am looking forward to fully understanding this code!

Votes

Translate

Translate

Report

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
Engaged ,
Dec 24, 2015 Dec 24, 2015

Copy link to clipboard

Copied

mickyhulse wrote:

Also, what doe the action actually do? I hate to sound ignorant, but I don't understand what exactly it does by just looking at the code.

What are the action parameters for?

I am looking forward to fully understanding this code!


Ok, so, I think I understand the basic logic of get_selected_layers:


  1. First for loop, you record existing layer visibility
  2. The call to make_action will make all selected layers visible and hide the rest (though, I don't yet understand how the action does this)
  3. Next for loop, you grab the selected visible layers
  4. Next for loop, you restore visibility
  5. Finally, return the selected layers array


Pretty dang cool!

Votes

Translate

Translate

Report

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
Engaged ,
Dec 24, 2015 Dec 24, 2015

Copy link to clipboard

Copied

Hi Qwertyfly...,

Your script works perfectly! I'm in the process of getting it to work with a BTM-based script. I'll update this thread if I make any significant progress.

A few questions … What does this code do(?):

app.userInteractionLevel;

... and:

UserInteractionLevel.DONTDISPLAYALERTS;

What is userInteractionLevel?

Also, in the action string, what do the hashes mean?

53637269707465645f416374696f6e73

53656c6563745f4c6179657273

4c61796572

1836411236

1937008996

1851878757

48696465204f7468657273

Does it matter what those strings are? Do they have any meaning?

Also, how did you make the action? I'm guessing you used the standard actions palette, and then saved/copied/pasted/converted the action code into the format we see in your script?

Sorry for all the questions. Just trying to fully grok your script.

Thanks again for the interesting and functional solution!


Cheers,

Micky

Votes

Translate

Translate

Report

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
Engaged ,
Dec 24, 2015 Dec 24, 2015

Copy link to clipboard

Copied

app.userInteractionLevel;

... and:

UserInteractionLevel.DONTDISPLAYALERTS;

What is userInteractionLevel?

Ah, I see what that is now.

That bit of code saves the current UserInteractionLevel and then temporarily turns off alerts. After executing the action your code resets the userInteractionLevel back to what it was before the script ran.

It's funny, I totally mis-read DONTDISPLAYALERTS as "don't display layer TS". Lol. That damn constant needs underscores for readability. Ha!

Votes

Translate

Translate

Report

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 ,
Dec 24, 2015 Dec 24, 2015

Copy link to clipboard

Copied

In the action strings, the hashes are hex-encoded words that the action language uses to store the various strings. The way this entire action string is obtained is by saving the action .aia file from the action panel and at that point you can read the .aia as a text file in a text editor. It's actually possible to alter the parameters of actions by changing these strings in some limited ways - some more useful than others - such as a file path of the destination file of a saving or exporting procedure!

Votes

Translate

Translate

Report

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
Engaged ,
Dec 24, 2015 Dec 24, 2015

Copy link to clipboard

Copied

Ah, I see! Thanks for the reply and explanation Silly-V‌!

I'm playing with action scripts now. I never really utilized actions in Illustrator before this. Pretty cool stuff.

Thanks again!!!!

Votes

Translate

Translate

Report

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
Guide ,
Dec 25, 2015 Dec 25, 2015

Copy link to clipboard

Copied

‌I think you've got the main gist of it. I'm happy to go through any parts your still un sure about. Only on the phone for today and tomorrow. So I'll be back on a computer after that and I'll bash together a bit of a rundown.

glad you like the script. It's good to know your going to get more out of it then just a script. your enthusiasm is great.

Votes

Translate

Translate

Report

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
Engaged ,
Dec 25, 2015 Dec 25, 2015

Copy link to clipboard

Copied

Qwertyfly... wrote:

I think you've got the main gist of it. I'm happy to go through any parts your still un sure about. Only on the phone for today and tomorrow. So I'll be back on a computer after that and I'll bash together a bit of a rundown.

glad you like the script. It's good to know your going to get more out of it then just a script. your enthusiasm is great.

Awesome! Thanks again Qwertyfly...‌!

I think I now understand most of the script.

If I had to pick one thing for you to explain in more detail, I'd love to know how you built the Action. I was able to convert the action string into an installable action:

/version 3
/name [
     4
     74656d70
]
/isOpen 0
/actionCount 1
/action-1 {
     /name [
          4
          74656d70
     ]
     /keyIndex 0
     /colorIndex 0
     /isOpen 0
     /eventCount 1
     /event-1 {
          /useRulersIn1stQuadrant 0
          /internalName (ai_plugin_Layer)
          /localizedName [
               5
               4c61796572
          ]
          /isOpen 0
          /isOn 1
          /hasDialog 0
          /parameterCount 3
          /parameter-1 {
               /key 1836411236
               /showInPalette -1
               /type (integer)
               /value 7
          }
          /parameter-2 {
               /key 1937008996
               /showInPalette -1
               /type (integer)
               /value 23
          }
          /parameter-3 {
               /key 1851878757
               /showInPalette -1
               /type (ustring)
               /value [
                    11
                    48696465204f7468657273
               ]
          }
     }
}

What is ai_plugin_Layer? What steps did you take to build this action?

When I inspect the action in the actions palette, it doesn't seem like there's much there to dissect.

Oh, and one thing I got wrong earlier …

The first for loop in your script records original layer visibility, but it also sets all layers to visible; I noticed the action doesn't work without this temporary step.

Thanks again for your help!

I was totally able to get your code to work with a BridgeTalk script I'm working on!

Thank you!!!!

Votes

Translate

Translate

Report

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
Guide ,
Jan 17, 2016 Jan 17, 2016

Copy link to clipboard

Copied

the script starts by making a list of what layers are visible and which are not.

while doing that it sets all layers to visible.

the action is then run which runs the Hide Others command.

now the script can tell you which ones are visible. these are the ones you had selected.

last of all it sets the original visibility of each layer using the list it created at the start.


the action was recorded in the usual way. then saved.

open that saved aia file with a text editor to get the action string.

it does need to be modified.

but all that take is to add ' to the start of each line.

and ', to the end of all lines, except the last just gets the '.

in essence, all we do is recreate the manually created aia file using JS.


sorry about the long wait for a reply, I've been off grid for a few weeks.

let me know if you want more info.

Votes

Translate

Translate

Report

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
Engaged ,
Jan 18, 2016 Jan 18, 2016

Copy link to clipboard

Copied

Thanks a billion for the reply Qwertyfly...‌, I greatly appreciate the help. And no worries on reply time. There's no pressure from me for replies … I totally understand how we can all get too busy to reply right away.

Thanks so much for the clarification on the code. I was able to successfully implement it in this plugin:

mhulse/illy-anim-redux - JavaScript - GitHub

I'm pretty satisfied with the end result. Thanks a bunch for your help!

the action is then run which runs the Hide Others command.

...

the action was recorded in the usual way. then saved.

That's interesting! Thanks so much for the details!

I hate to keep bugging you, but where would I find the "Hide Others" command? I see something like that under the Illustrator CC menu, but I thought that was an application-wide thing on OS X?

Thanks again (to everyone) and Qwertyfly...‌ for the help!!! I greatly appreciate the assist.

Votes

Translate

Translate

Report

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
Guide ,
Jan 18, 2016 Jan 18, 2016

Copy link to clipboard

Copied

select some layers, then in the flyout menu of the layers panel you will find the hide others...

Capture.JPG

Votes

Translate

Translate

Report

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
Engaged ,
Jan 18, 2016 Jan 18, 2016

Copy link to clipboard

Copied

LATEST

Ahhhhh! I don't think I would have ever looked there. Hehehe! Thanks Qwertyfly...‌!

Votes

Translate

Translate

Report

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
Engaged ,
Dec 21, 2015 Dec 21, 2015

Copy link to clipboard

Copied

Wow! Thanks for the replies everyone!!! I really appreciate the help!

I'm going to play around with all the ideas/code mentioned in this thread and I'll be back with my findings.


Thanks again for taking the time to help out!

Also, Qwertyfly...‌, your code looks really cool! You're creating an action on the fly? That's so interesting! I am looking forward to testing the code. Seems like that technique could really open the doors to a whole bunch of cool scripting ideas.

I'll be back!

Thanks again.

Cheers,

M

Votes

Translate

Translate

Report

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
Guide ,
Dec 21, 2015 Dec 21, 2015

Copy link to clipboard

Copied

I love the ability to include actions in js scripts, it opens so many possibles.

I do the same with VB.

shame VB is not supported on mac.

as this action is only used once this is fairly straight forward,

there are a few other tricks for actions you want access to multiple time in a script to help speed things up.

Hope it does what your after.

Let me know if you need any help implementing it with the rest of your script

Votes

Translate

Translate

Report

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