Highlighted

Selecting an Object inside a group which is inside a layer

Community Beginner ,
Jun 02, 2020

Copy link to clipboard

Copied

I've a file like this

Object (Layer Name)

> Text

> Main files

> Design

    >        <Group>

          <Path>

> Background

 

Now I want to select only <Path> .

I have a script that will select the Main group (Design) which looks like this

 

var docRef = app.activeDocument;
var layers = docRef.layers;
var myLayer = layers["Objects"]; //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<docRef.groupItems.length;a++){
if (docRef.groupItems[a].name == "Design"){
docRef.groupItems[a].selected = true;
}
}

 

Can anyone help me to make that script?

 

I want to select <Path> file and change it color to a solic/gradient color.

 

Topics

Scripting

Views

765

Likes

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

Selecting an Object inside a group which is inside a layer

Community Beginner ,
Jun 02, 2020

Copy link to clipboard

Copied

I've a file like this

Object (Layer Name)

> Text

> Main files

> Design

    >        <Group>

          <Path>

> Background

 

Now I want to select only <Path> .

I have a script that will select the Main group (Design) which looks like this

 

var docRef = app.activeDocument;
var layers = docRef.layers;
var myLayer = layers["Objects"]; //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<docRef.groupItems.length;a++){
if (docRef.groupItems[a].name == "Design"){
docRef.groupItems[a].selected = true;
}
}

 

Can anyone help me to make that script?

 

I want to select <Path> file and change it color to a solic/gradient color.

 

Topics

Scripting

Views

766

Likes

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
Jun 02, 2020 0
Contributor ,
Jun 02, 2020

Copy link to clipboard

Copied

How do you plan to select "Path"?  Do you plan to selct it based on it's name ("Path")?  Do you plan to selct it based on it being the bottom-most item in the "Design" group?  Do you plan on selecting it based on it being a non-group item in the "Design" group? ...

Likes

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
Reply
Loading...
Jun 02, 2020 1
Adobe Community Professional ,
Jun 02, 2020

Copy link to clipboard

Copied

Hi, Could you give more explanation

What is

  • Text ? Is it textframe
  • Main Files ? is it group or layer with name "Main files" or something else
  • What do you mean by "I want to select <Path> file", What is Path file? It is path or a file?

If you provide more information, then we can help to select the path inside the group, also which path you want to slelect, there can be more paths inside the group. Is there any specifc name of the Path.

 

If you can share screenshot of the layers panel of your design that would be great.

 

Best regards

Likes

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
Reply
Loading...
Jun 02, 2020 1
Adobe Community Professional ,
Jun 02, 2020

Copy link to clipboard

Copied

If your design looks like attached screen shot and assuming there is only single path inside the main group "Design", then following snippet will work to select the path

 

Screenshot 2020-06-02 at 11.15.02 PM.png

 

var docRef = app.activeDocument;
var layers = docRef.layers;
var layerName = "Objects";
docRef.selection = null;  //ensure there is nothing in the document selected already. this way you only get the selection you want.
try {
    var myLayer = layers.getByName(layerName); //this defines the layer that you want to get the selection from
    for (var a = 0; a < docRef.groupItems.length; a++) {
        if (docRef.groupItems[a].name == "Design") {
            var pathItems = docRef.groupItems[a].pathItems;
            if(pathItems.length ==  1){
                pathItems[0].selected = true;
            }
        }
    }
} catch (e) {
    alert("Layer with name - " + layerName + " doesn't exists");
}

 

If you have different work flow scenario, please let us know

 

Best regards

Likes

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
Reply
Loading...
Jun 02, 2020 2
Enthusiast ,
Jun 02, 2020

Copy link to clipboard

Copied

 

 

Salut!

    app.selection = null;
    var docRef = app.activeDocument;    
    try{
          var myLayer = docRef.layers["Objects"];
           myLayer.groupItems["Design"].selected = true;
    }
	catch(e){
           beep(); //comment...
	}

Avec un peu de chance, si j'ai bien compris ?

elleere

Likes

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
Reply
Loading...
Jun 02, 2020 0
Community Beginner ,
Jun 02, 2020

Copy link to clipboard

Copied

I can't understand what are you saying. Can you plz translate into English?

Likes

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
Reply
Loading...
Jun 02, 2020 0
Adobe Community Professional ,
Jun 03, 2020

Copy link to clipboard

Copied

Hi,

You can use translate option available here 🙂 May be you have noticed that. 🙂

Best regards

Likes

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
Reply
Loading...
Jun 03, 2020 0
Community Beginner ,
Jun 02, 2020

Copy link to clipboard

Copied

rahative_0-1591160818332.png

 

<Path> is the name of that file. I want to select that file.

Likes

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
Reply
Loading...
Jun 02, 2020 0
Contributor ,
Jun 02, 2020

Copy link to clipboard

Copied

At present, <Path> (between angle brackets) is nameless. If you want to reference a path by name, you will have to name it. Once you name it (for example, Path, without angle brackets), you can select it as

 

 

app.activeDocument.layers["Objects"].groupItems["Mandala"].pathItems["Path"].selected = true;

 



Likes

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
Reply
Loading...
Jun 02, 2020 1
Community Beginner ,
Jun 03, 2020

Copy link to clipboard

Copied

It's not working 😞

Likes

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
Reply
Loading...
Jun 03, 2020 0
Adobe Community Professional ,
Jun 03, 2020

Copy link to clipboard

Copied

femkeblanco, solution will also work in your scenario but another way of doing it where we alert user if in case oath or group or layer does not exists with name specified in the script.

 

 

#target illustrator
var docRef = app.activeDocument;
var layers = docRef.layers;
var layerName = "Objects";
var groupName = "Mandala";
var pathName = "Path";
docRef.selection = null;  //ensure there is nothing in the document selected already. this way you only get the selection you want.
try {
    var myLayer = layers.getByName(layerName); //this defines the layer that you want to get the selection from
    try {
        var _groupItem = myLayer.groupItems.getByName(groupName);
        try {
            var _pathItem = _groupItem.pathItems.getByName(pathName);
            _pathItem.selected = true;
        } catch (e) {
            alert("Path with name - " + pathName + " doesn't exists");
        }
    } catch (e) {
        alert("Group with name - " + groupName + " doesn't exists");
    }
} catch (e) {
    alert("Layer with name - " + layerName + " doesn't exists");
}

 

 

Let us know if this helps you.

Best regards

Likes

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
Reply
Loading...
Jun 03, 2020 1
Community Beginner ,
Jun 03, 2020

Copy link to clipboard

Copied

rahative_0-1591194067342.png

I tried your code but it's showing this. 

I'm sorry for replying late. The time zone is a bit different in my country 😞

Likes

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
Reply
Loading...
Jun 03, 2020 0
Adobe Community Professional ,
Jun 03, 2020

Copy link to clipboard

Copied

No worries,

The error that you getting, is because "Path" is not actually the pathItem of the Illustrator. So you said this is a file with name "Path", what type of file it is. I would prefer if you can share your ai file, we can help you easily. By looking into your screen shot, "Path" seems to be a group.

 

Best regards

Likes

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
Reply
Loading...
Jun 03, 2020 0
Contributor ,
Jun 03, 2020

Copy link to clipboard

Copied

Both bits of code work for me.

 

Untitled.jpg

Are "Mandala" and "Path" definitely a groupItem and pathItem, respectively?  You can test them: 

 

alert(app.activeDocument.layers["Objects"].groupItems["Mandala"].typename);

 

 

alert(app.activeDocument.layers["Objects"].groupItems["Mandala"].pathItems["Path"].typename);

 

Do the alerts say "GroupItem" and "PathItem"? 

Likes

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
Reply
Loading...
Jun 03, 2020 0
Adobe Community Professional ,
Jun 03, 2020

Copy link to clipboard

Copied

Also, I just noticed, there is a difference in your first and second screenshot, regarding the Path. You can check, first screen shot does not have arrow icon left to the Path, and second screen shot with error alert, have arrow icon on left of the "Path". What I understand it can be anything with name "Path". Please correct me if I am wrong anywhere in understanding your flow.

 

If that is the case, then update the following line in the above script

 

 var _pathItem = _groupItem.pathItems.getByName(pathName);

to

 var _pathItem = _groupItem.pageItems.getByName(pathName);

 

Let us know if this works for you.

 

Best regards

Likes

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
Reply
Loading...
Jun 03, 2020 0
Contributor ,
Jun 03, 2020

Copy link to clipboard

Copied

Yes, it appears that Path in the second screenshot is a groupItem and not a pathItem.

Likes

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
Reply
Loading...
Jun 03, 2020 0