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

specific colour swatches are grouped in that folder

New Here ,
Sep 25, 2024 Sep 25, 2024

Copy link to clipboard

Copied

hello,
I'm new to programming and I'm trying to create a .jsx to make an action where a folder is created and some specific colour swatches are grouped in that folder.

So far I have only been able to create the folder, but I don't know how to make the colour swatches to be selected and put inside this folder.

Could someone help me?

 

thanks

TOPICS
Scripting , Tools

Views

405

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 1 Correct answer

Community Expert , Oct 03, 2024 Oct 03, 2024

Well the script works perfectly for me. I chose all the "BM" swatches to add to a swatch group:

Before scriptBefore scriptAfter scriptAfter script

 

Here is the exact script I used:

 

(function () {

    // get reference to active document
    var doc = app.activeDocument;

    // get reference to each color swatches I want, stored in array
    var mySwatches = [
        doc.swatches.getByName('BM BLACK'),
        doc.swatches.getByName('BM WHITE'),
        doc.swatches.getByName('BM BROWN'),
        doc.swatches.getByN
...

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 25, 2024 Sep 25, 2024

Copy link to clipboard

Copied

Hi @monica_5152, here is some code to show you the basics. It will work with the demo.pdf file attached.

(function () {

    // get reference to active document
    var doc = app.activeDocument;

    // get reference to each color swatches I want, stored in array
    var mySwatches = [
        doc.swatches.getByName('CMYK Red'),
        doc.swatches.getByName('CMYK Yellow'),
        doc.swatches.getByName('CMYK Green'),
        doc.swatches.getByName('CMYK Cyan'),
        doc.swatches.getByName('CMYK Blue'),
        doc.swatches.getByName('CMYK Magenta'),
    ];

    // create a swatch group
    var mySwatchGroup = doc.swatchGroups.add();
    mySwatchGroup.name = 'Excellent CMYK Colors';

    // add my swatches to the color group
    for (var i = 0; i < mySwatches.length; i++) {
        mySwatchGroup.addSwatch(mySwatches[i]);
    }

})();

 

You will need to look at the scripting API documentation, such as for Swatch, Swatches, SwatchGroup, SwatchGroups.

 

Good luck!

- Mark

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
New Here ,
Sep 26, 2024 Sep 26, 2024

Copy link to clipboard

Copied

Hii 🙂 , thank you very much for the answer...Although unfortunately it doesn't work for me, I think the problem is that my swatches are not CMYK, they are spot colours (pantones, etc)...Is it possible that this is the error?

Thank you very much

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 ,
Sep 26, 2024 Sep 26, 2024

Copy link to clipboard

Copied

Oh, so what happens when you run the script? Do you get an error? I just converted some colours in my demo document into spots and also non-globals and the code worked perfectly. If you look at the docs for SwatchGroup, there is an "addSpot" method. We probably don't need it if your colours are already in swatches.

 

Maybe you could post a little demo document with your colours, and include the code you are using? We'll get to the bottom of it!

- Mark

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
New Here ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

Hi!
Well the other part I have done it by illustrator actions. basically is to delete the samples that are not used. but then I would like that the remaining ones are grouped in a folder, to be able to do it all from an action.

this is the error that comes out when i run the script.

 

I don't know if it is possible to do that.

Anyway, thank you very much for your help. 🙂

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 ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

Hi @monica_5152 , @m1b  script would work irrespective of the type of the swatch as CMYK or RGB.  You need to use the name of the your swatches in place of 'CMYK Red', 'CMYK Yellow', etc. like below

(function () {

    // get reference to active document
    var doc = app.activeDocument;

    // get reference to each color swatches I want, stored in array
    var mySwatches = [
        doc.swatches.getByName('BM BLACK'),
        doc.swatches.getByName('BM RED'),
        doc.swatches.getByName('BM GOLD'),
        doc.swatches.getByName('BM SILVER'),
    ];

    // create a swatch group
    var mySwatchGroup = doc.swatchGroups.add();
    mySwatchGroup.name = 'Excellent CMYK Colors';

    // add my swatches to the color group
    for (var i = 0; i < mySwatches.length; i++) {
        mySwatchGroup.addSwatch(mySwatches[i]);
    }

})();

 

The error that you are getting it may be of the following. reason:

1. By mistake array of swatches is not closed correctly and var keyword is not used at proper statment.

2. You have not updated the swtaches names in teh script as per the AI document.

Best regards

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
New Here ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

yes! i did that but it still doesn't do what i want, i mean it creates the folder but doesn't insert the swatches inside the folder.... I have changed the names to the ones I have in the swatches list, I have even changed the names of the swatches themselves, but it doesn't work, is it possible that it is because the document is an .ait?

 

I think it's not a problem of the names of the swatches, they are exactly the same... I don't know what it can be...

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 ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

Hi @monica_5152 could you please post an example .ait file for us to try script with? It will be easy to solve I think.

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
New Here ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

yes! I'm attaching it here, (type the .ait, remove .pdf)
Hopefully it will be solved
Thanks

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 ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

Well the script works perfectly for me. I chose all the "BM" swatches to add to a swatch group:

Before scriptBefore scriptAfter scriptAfter script

 

Here is the exact script I used:

 

(function () {

    // get reference to active document
    var doc = app.activeDocument;

    // get reference to each color swatches I want, stored in array
    var mySwatches = [
        doc.swatches.getByName('BM BLACK'),
        doc.swatches.getByName('BM WHITE'),
        doc.swatches.getByName('BM BROWN'),
        doc.swatches.getByName('BM RED'),
        doc.swatches.getByName('BM GOLD'),
        doc.swatches.getByName('BM GOLD132'),
        doc.swatches.getByName('BM SILVER'),
        doc.swatches.getByName('BM BLUE'),
        doc.swatches.getByName('BM GREEN'),
        doc.swatches.getByName('BM YELLOW'),
        doc.swatches.getByName('BM BLUE LA CAIXA'),
    ];

    // create a swatch group
    var mySwatchGroup = doc.swatchGroups.add();
    mySwatchGroup.name = 'Excellent CMYK Colors';

    // add my swatches to the color group
    for (var i = 0; i < mySwatches.length; i++) {
        mySwatchGroup.addSwatch(mySwatches[i]);
    }

})();

 

 

Do you get the same result from this script? Maybe you need to share your exact script so we can test it with your sample document.

- Mark

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
New Here ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

Hello Mark, 🙂

 

I think the problem was that I had the ‘clear swatches’ action before the selection. I've changed the action and first I've set it to select the swatches and then to clean them. Everything is working fine! Thank you very much ^^ you have helped me a lot.

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 ,
Oct 04, 2024 Oct 04, 2024

Copy link to clipboard

Copied

LATEST

Glad to hear! Good luck with your scripting!

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