Copy link to clipboard
Copied
Is there a script out there that allows you to move all selected objects to the current/ active layer?
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);
}
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);
}
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.
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
Copy link to clipboard
Copied
here's another way
app.executeMenuCommand("Selection Hat 2");
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.
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.
are there any volunteers who want to post an updated list from 2021 SDK?
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. 🙂
Copy link to clipboard
Copied
hahaha the year is still young though
Copy link to clipboard
Copied
Hi @CarlosCanto
but for sure we have our "personal" documentation for SelectionHat'XX' in the same thread you mentioned.
😉
By the way: This has been one of my favorite threads for years.
Copy link to clipboard
Copied
This is the list I use
This is a post by @ philipv71883047 in which he describes how he found an argument.
Copy link to clipboard
Copied
thanks femkeblanco, ten's list if a bit newer (cc2018) than the one I'm using
Copy link to clipboard
Copied
definitely in my top 3 threads of all time
Copy link to clipboard
Copied
… which started with a simple question about the correct syntax …
😄
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.
Copy link to clipboard
Copied
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.