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

Select all objects on same layer for nested layers

Community Beginner ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

The select all objects on same layer function selects all objects on nested layers, instead of just a particular set of objects on a sublayer. That is because they are part of the same parent layer.

 

For example in this layer structure:

 

Layer 1

    Sublayer 1

    Sublayer to select

    Sublayer 3

 

If I want to select all objects on the layer: "Sublayer to select" with one of the objects on the layer selected, it selects the other sublayers too. Does anyone have a script that, based on the selected object, selects all objects of the layer on which the selected object resides, without selecting any of the other sublayers?

 

 

 

TOPICS
Feature request , Scripting

Views

1.3K

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
Adobe
Guide ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

 

var doc = app.activeDocument;
var sel = app.selection;
for (var i = 0; i < doc.pageItems.length; i++) {
    if (doc.pageItems[i].layer == sel[0].layer) {
        doc.pageItems[i].selected = true;
  }
}

 

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
Community Expert ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

this could be an extremely slow method of doing this. The way illustrator scopes items means that if you get all the pageItems of the activeDocument, you're getting every single item even if it's nested deep inside a complex group or compound path.. a relatively simple document can really drag if you process each individual page item of the document scope. The ideal way of handling this is to ensure you're only processing container objects (group,compoundPath) and not all the child elements of. that container.

 

If you access the items by layer instead, the scope changes, and suddenly "pageItem" only refers to top level items in the layer, so you can be as efficient as possible. Imagine there's only one groupItem in the document.. but it has 10,000 paths/groups/compound paths/etc inside it. If you loop the document pageItems, you're going to process every single one of those 10,000 child elements. If you loop the layer pageItems, you'll only process one object saving you a boatload of time and headaches.

 

Hope this is helpful to someone. 😃

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 ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

You're right.  What about

 

var doc = app.activeDocument;
var sel = app.selection;
var targetLayer = sel[0].layer;
targetLayer.hasSelectedArtwork = true;

 

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
Community Expert ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

This'll work. It's not very robust.. You'll likely need some logic to actually determine the correct layer, because i'm sure you don't want to be manually renaming the desired sublayer to "Sublayer To Select" every time.. Assuming the layers aren't name, but you know where they are in the stacking order, can select the layers by index instead, like this: 

layers[0].layers[1].hasSelectedArtwork = true;

 

 

function selectSubLayer()
{
	var doc = app.activeDocument;
	var layers = doc.layers;

	var layerToSelect = layers["Layer 1"].layers["Sublayer To Select"];
	layerToSelect.hasSelectedArtwork = true;
}
selectSubLayer();

 

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
Community Expert ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

It's not a script, but this simple action will also do what you are looking for.

 

https://drive.google.com/file/d/1iboxQmQqY5dSgXZoWyJxd8Hnf-9XFlht/view?usp=sharing

 

Note that it may not work in older versions of Illustrator.

 

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
Community Expert ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

quote

The select all objects on same layer function selects all objects on nested layers,

 

can you post the function you're using? I don't remember seing a selectAllObjectsOnSameLayer() function.

 

this works the the way you want if you have an object already selected

activeDocument.activeLayer.hasSelectedArtwork = true;

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
Community Beginner ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

Thanks @CarlosCanto, I was wondering, can I hotkey this script? It does not record as an action.

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
Community Expert ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

create a new action and begin recording

at the top right corner of the actions panel, click the menu button

then click "Inser Menu Item"

then go to your script under the File > Scripts menu (i believe this only works if you have the script in your scripts folder, and not if you're trying to use "Other Script". but i could be wrong)

stop recording action

set your desired hotkey to action

press hotkey

enjoy

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
Community Beginner ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

LATEST

This works really well, thanks a bunch!

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
Community Expert ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

I don't think that this will work, Carlos.

 

The command that default is referring to is the Select menu > Object > All on the same Layers.

 

It does not respect sublayers.

 

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
Community Expert ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

Sorry, Carlos. I was answering in the wrong thread.

 

Your script does work, of course.

 

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
Community Expert ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

oh I see, thanks for pointing that out Kurt, I thought the OP was using a javascript function instead of a menu command.

 

there is a javascript equivalent that selects all on the same layer, but as mentioned it does select all items in layers and sublayers

app.executeMenuCommand("Selection Hat 3");

 

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