how to write an action selecting multiple objects in illustrator

Community Beginner ,
Jun 12, 2022 Jun 12, 2022

Copy link to clipboard

Copied

hi,

i am trying to write an action to select objects in illustrator. i have attached a screenshot to show what i am trying to do...

20220612.png

i tried to pick the two objects, both named as cap in the Layer 1 as shown in the picture, but the action is not recording as an item...

how can i get the action to record as an item to be able to select both "cap" objects?...

please comment and help to get it done...

cheers and thanks...

TOPICS
How to , Scripting

Views

337

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

correct answers 2 Correct answers

Advisor , Jun 12, 2022 Jun 12, 2022

This will select any page items named "Cap" in layer "Layer 1".  (I presume these are groups or compound paths.)

var items = app.activeDocument.layers["Layer 1"].pageItems;
for (var i = 0; i < items.length; i++) {
    if (items[i].name == "Cap") {
        items[i].selected = true;
    }
}

 

Likes

Translate

Translate
Community Expert , Jun 18, 2022 Jun 18, 2022

Here's a modified version of @femkeblanco's earlier script. This time it removes 'canvas' named items. I changed the order of the loop to go backwards, because the item collection indices will be messed if I remove the items from the start first.

- Mark

var items = app.activeDocument.pageItems;
for (var i = items.length - 1; i >= 0; i--) {
    if (items[i].name == "canvas") {
        items[i].remove();
    }
}

 

Likes

Translate

Translate
Community Expert ,
Jun 12, 2022 Jun 12, 2022

Copy link to clipboard

Copied

Unfortunately, this cannot be done with an action.

 

A script would be required.

 

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
Community Beginner ,
Jun 12, 2022 Jun 12, 2022

Copy link to clipboard

Copied

kurt,

can a script works within action? ... how to write a script so it works to select both "cap" object? ... i have no knewledge in writing script...

cheers and thanks

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
Community Expert ,
Jun 12, 2022 Jun 12, 2022

Copy link to clipboard

Copied

Yes, a script can be incorporated in an action.

 

Some of the scripting experts may chime in and provide something.

 

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
Advisor ,
Jun 12, 2022 Jun 12, 2022

Copy link to clipboard

Copied

This will select any page items named "Cap" in layer "Layer 1".  (I presume these are groups or compound paths.)

var items = app.activeDocument.layers["Layer 1"].pageItems;
for (var i = 0; i < items.length; i++) {
    if (items[i].name == "Cap") {
        items[i].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
community guidelines
Community Beginner ,
Jun 12, 2022 Jun 12, 2022

Copy link to clipboard

Copied

hi advisor,

how can i incorporated this script to my action?

please advise...

cheers and thanks

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
Community Expert ,
Jun 12, 2022 Jun 12, 2022

Copy link to clipboard

Copied

Hi @wong168,

Try this:

1. Save FemkeBlanko's script as a plain text file, call it eg. "Select Caps.js". Put it into the Presets/Scripts folder of your Adobe Illustrator installation (and re-launch Illustrator). Check that it appears under the File > Scripts menu.

2. In the Actions panel, select a step in your action and choose "Insert Menu Item..." from the panel menu. Then choose File > Scripts > Select Caps.

 

This will add a script step that will run the script. Be aware that if you export the action to send away, you will need to send the script too.

- Mark

 

P.S. Here's another way that doesn't require scripts, but it only works for you if you have control over the files and are able to add the Note in advance:

1. Make sure the caps have the word "CAP" in their "Note". (Attributes panel).

2. Add step to your action by choosing "Select Object" from the Actions panel menu and entering "CAP" text. See screenshot below.

Screen Shot 2022-06-13 at 10.12.53 am.png

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
Community Beginner ,
Jun 12, 2022 Jun 12, 2022

Copy link to clipboard

Copied

mark,

to add the script to the action is not working for the cap, it is not picking the cap...

but your suggestion to add the note CAP to the attributes panel is working well ... the problem now is to add the CAP  to the attributes panel ... can this be automated with action or not?... 

thanks for your help...

cheers,

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
Community Expert ,
Jun 12, 2022 Jun 12, 2022

Copy link to clipboard

Copied

First let's find out why femkeblanco's script isn't selecting the caps. Try this version:

 

alert('Yay! The script is working so far');
var items = app.activeDocument.layers["Layer 1"].pageItems;
for (var i = 0; i < items.length; i++) {
    if (items[i].name == "Cap") {
        items[i].selected = true;
        alert ('Selected a cap (item ' + i + ')');
    }
}

 

It will show an alert when it runs and also when it selects a cap. Can you also double-check that you have a layer called "Layer 1" and the "Cap" items are on that layer and that their names are "Cap" not for example "Cap " (with a space).

- Mark

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
Community Beginner ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

mark,

tried your version of script ... it did show "yay! the script is working so far" ... it did show "selected a cap (item 2)" ... it also did show "selected a cap (item 11)" ... but it did not rotate the cap and it rotated both the cap and the shirt as shown in the attached screenshot...Screen Shot 2022-06-13 at 17.53.20.png

if you count from my first screenshot, the first cap should be item 3 and the second cap is item 12 ... it seems to be selected the item above ... am i correct???

cheers and thanks...

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
Community Beginner ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

mark,

the script is working now ... after i added the item "deselect" in the Action...

thanks for your help...

cheers,

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
Community Beginner ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

Screen Shot 2022-06-13 at 18.10.31.png

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
Community Expert ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

Yes the script doesn't empty the selection—I wasn't sure if you wanted it to.

Great to hear it's working. We got there in the end! 🙂

- Mark

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
Advisor ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

@m1b Thanks for your input, Mark.  I think it's a bit undue that my answer was marked correct while you did most of the work in getting the OP to his goal. 

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
Community Expert ,
Jun 14, 2022 Jun 14, 2022

Copy link to clipboard

Copied

Haha, all good. I honestly learn something from every question. All that stuff in my post above—it was all new to me. I'm totally a novice at Actions. Appreciate your kind thought though. 🙂

- Mark

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
Community Beginner ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

hi,

i like to continue to work on this job to delete "canvas" in the file ... i tried to do it in action but not working...

i think it should be working with the script ... but i do not know how to write this script ... can you help?...

there might be 2, 3 or 4 "canvas" in the file...

thanks and cheers,

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
Community Expert ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

Hi @wong168, what is a "canvas"? A page item named "canvas"? An artboard? And you want to remove all of them?

- Mark

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
Community Beginner ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

mark,

a page item named "canvas", it is not an artboard...

yes, remove all of them ... there is nothing in the page...

thanks and cheers,

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
Community Expert ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

Here's a modified version of @femkeblanco's earlier script. This time it removes 'canvas' named items. I changed the order of the loop to go backwards, because the item collection indices will be messed if I remove the items from the start first.

- Mark

var items = app.activeDocument.pageItems;
for (var i = items.length - 1; i >= 0; i--) {
    if (items[i].name == "canvas") {
        items[i].remove();
    }
}

 

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
Community Beginner ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

mark,

thanks for your help ... will try it out to see if it work...

thanks and cheers,

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
Community Beginner ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

LATEST

mark,

it works perfectly, even with five "Canvas" ... changed "canvas" to "Canvas"...

thanks for your help...

cheers,

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
Community Expert ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied


@wong168 wrote:

but your suggestion to add the note CAP to the attributes panel is working well ... the problem now is to add the CAP  to the attributes panel ... can this be automated with action or not?... 

 

I don't see how this could be done. It is a circular problem—if the action could target the Cap to give it a note, you could just tell the action to select it.

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
Community Expert ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

Wong,

 

as I (and Mark as well) already stated: You cannot select items with an action based on their names in the Layers palette. It would be beneficial, but currently it is just not possible and unfortunately I doubt that it may be incorporated soon.

 

Notes in the Attributes palette are very useful, especially if you are going to select certain objects repeatedly during running actions. But they have to be already there or they may be created as part of an action based on unique appearance attributes.

 

In your case (considering the screenshot you provided) it rather looks that the cap objects have no unique attributes and therefore it is not possible to "catch" them in order to assign notes.

 

Sometimes there may be some tricks to do it despite the general action inability, but to check that, normally a couple of sample Illustrator files have to be shared in order to have a look.

 

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
Community Expert ,
Jun 14, 2022 Jun 14, 2022

Copy link to clipboard

Copied

"I think it's a bit undue that my answer was marked correct while you did most of the work in getting the OP to his goal."

 

Femke,

 

some (perhaps inane) notes about so-called "correct" answers:

 

As Mark already stated, it's all good, at least if one doesn't take the entire rating system too seriously. Since its advent about eight years or so ago, the rating system has been of course error-prone due to different reasons. For example, there are a lot of questioners who immediately mark the first reply to their requests as "correct", probably just in terms of "yeah, there is an answer and it's correct or very nice that there is one". They do not necessarily mean that it is technically or functionally "correct".

 

Then there are other cases and some questioners may just not be able to evaluate the answers they received and therefore just mark an "arbitrary" answer as "correct". And there are some other mysterious cases.

 

I'm even pretty sure that there are a lot of "correct" answers in the Adobe forums which are actually "wrong" or at least misleading.

 

Frankly, I still do not like the rating system and always voted against it, but in the end it succeeded for whatever reason.

 

Your answer in this thread definitely deserves the "correct" badge. Mark knows that and as a gentleman he just did the "dirty work" for you, so we can move on to some other challenges. ::-)

 

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
Advisor ,
Jun 15, 2022 Jun 15, 2022

Copy link to clipboard

Copied

Thanks @Kurt Gold.  I agree.  

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