Script to move objects to the current layer

Community Beginner ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

Is there a script out there that allows you to move all selected objects to the current/ active layer?

TOPICS
How to, Scripting, Third party plugins

Views

203

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

Copy link to clipboard

Copied

 

var doc = app.activeDocument;
var sel = app.selection;
for (var i = 0; i < sel.length; i++) {
    if (sel[i].parent.typename == "GroupItem" || 
        sel[i].parent.typename == "CompoundPathItem") {
        continue;
    }
    sel[i].moveToEnd(doc.activeLayer);
}

 

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
community guidelines
Adobe Community Professional ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

If you're moving objects from one layer to another, you need to make sure you loop them backwards or some objects might be left behind. I'm also not sure why you have a conditon in there to skip compound paths and groups? The post didn't mention that. Edit*** i'm dumb. I see what you're doing now. 

OP, try this:

 

var doc = app.activeDocument;
var sel = app.selection;
for (var i = sel.length-1; i >=0; i--) {
    if (sel[i].parent.typename == "GroupItem" || 
        sel[i].parent.typename == "CompoundPathItem") {
        continue;
    }
    sel[i].moveToBeginning(doc.activeLayer);
}

 

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

Copy link to clipboard

Copied

You're right.  Skipping group members was unnecessary here because "selection" consists of top levels items.  This is contrary to pageItems (which is what I was thinking of), which consists of groups and group members themselves. 

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
community guidelines
Adobe Community Professional ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

Not that I want to hijack the scripting division, but alternatively this simple action will also do it.

 

https://drive.google.com/file/d/1LmSeRPU4hXCyF4VdjYGliGpyP-L0GYFd/view?usp=sharing

 

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
community guidelines
Adobe Community Professional ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

here's another way

 

app.executeMenuCommand("Selection Hat 2");

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
community guidelines
Adobe Community Professional ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

Is there any documentation about this aside from just the name of the command and the argument passed?

 

I'm glad the executeMenuCommand function exists... But it's exceedingly frustrating that the arguments are all over the map in terms of caps, spacing, and just overall unhelpful names... Some arguments are camel case. Some are pascal case. Some lowercase, some title case, some with spaces.. Wtf?! And aside from that, what on earth does "selection hat 3" mean?hpw is it different than selection hat 2 or selection hat 97? Is it an abbreviation for something? Is it just a shortened word?

 

How on earth are we supposed to learn these things so that we can use them effectively if there's no documentation? Just trying each command out on a myriad of different possible situations is not acceptable.

 

End of rant. 

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
community guidelines
Adobe Community Professional ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

Hi Dillian, no there's no documentation unfortunately. I remember when this command was introduced in CS6, it was so great that we didn't care we couldn't use half of the commands because we didn't know what they did...at least I didn't. So I started playing with all of them just to try to figure out their usage, it was a fun trial and error exercise.

 

https://community.adobe.com/t5/illustrator/js-cs6-executemenucommand/m-p/5904747#M19648

 

then a few years later, shalakobell posted a new list with descriptions, it was very useful. It is the last list I have, I still use it as is.

https://community.adobe.com/t5/illustrator/a-list-of-illustrator-menu-commands-we-can-call-from-java...

 

are there any volunteers who want to post an updated list from 2021 SDK?

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
community guidelines
Adobe Community Professional ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

Carlos, I'm pretty sure that your single line script is going to be the script of the year 2021. 🙂

 

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
community guidelines
Adobe Community Professional ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

hahaha the year is still young though

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
community guidelines
Adobe Community Professional ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

Hi @CarlosCanto 

but for sure we have our "personal" documentation for SelectionHat'XX' in the same thread you mentioned.

😉

 

[JS] CS6+ executeMenuCommand 

 

By the way: This has been one of my favorite threads for years.

 

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

Copy link to clipboard

Copied

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
community guidelines
Adobe Community Professional ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

thanks femkeblanco, ten's list if a bit newer (cc2018) than the one I'm using

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
community guidelines
Adobe Community Professional ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

definitely in my top 3 threads of all time

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
community guidelines
Adobe Community Professional ,
Apr 03, 2021 Apr 03, 2021

Copy link to clipboard

Copied

… which started with a simple question about the correct syntax …

😄

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
community guidelines
Adobe Community Professional ,
Apr 04, 2021 Apr 04, 2021

Copy link to clipboard

Copied

Yesterday I inspected the entire execute menu command list for the first time.

 

I have to agree with Dilliam: It is a pretty chaotic smorgasbord that probably needs some structuring very soon. That may be true for the entire application.

 

Admittedly, I do like the "hat" commands and wouldn't change them.

 

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
community guidelines
Adobe Community Professional ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

LATEST

i'm not saying i don't like the hat commands.. I'm just saying that compared to commands like "selectall" or "lockguide" which are descriptive, "selection hat #" is not descriptive at all. unless "hat" stands for something that i'm unaware of? Even if it does, it still doesn't make sense, really.. Sometimes selection hat refers to how to select some items. sometimes it refers to what to do with already selected items. And since all of the selection hat commands are differentiated only by integers that seem to represent nothing other than the sequence in which the devs wrote those commands, it just seems like a really suboptimal way of labeling these.

 

If adobe wanted to, it seems as though it would be exceedingly simple to duplicate those commands and give them a more consistent and meaningful naming schema. They could leave the existing commands alone to prevent breaking any legacy code, but then include the same commands with good names so that future development makes a little bit more sense.

 

I'd also love the ability to disable the creation of undo states when performing certain menucommands. If there's an error during a script, i'd like to be able to undo, fix the issue, then run the script agin.. But sometimes, depending on the script, you'll be required to undo several (or even dozens) of times to get back to the original state.

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
community guidelines