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

How to apply swatches into document via script?

Explorer ,
Mar 02, 2017 Mar 02, 2017

Copy link to clipboard

Copied

Every day i have to do this steps many times:

1. Window -> Swatches -> Other Libraries -> "Select MySwatches.ai from Computer".

2. Then i click on swatches to apply them into swatch list

SwatchApply.jpg

Can u tell me please, how to apply swatches into document via script, if it possible?

TOPICS
Scripting

Views

3.0K

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
Valorous Hero ,
Mar 03, 2017 Mar 03, 2017

Copy link to clipboard

Copied

Yea it's possible, a script can open your swatch file and copy all the swatches over. However, if your issue is putting them into a new document, you could alter one of the new document profiles to include the swatches so that your new default documents will already have them.

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
Explorer ,
Mar 03, 2017 Mar 03, 2017

Copy link to clipboard

Copied

Hello, dear Silly-V!

Unfortunately, all the documents I work with are not new. Please, tell me how to do this for already created documents.

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
Explorer ,
Mar 10, 2017 Mar 10, 2017

Copy link to clipboard

Copied

I found how to open swatches, but can't find how to copy them. Please take a look.

#target Illustrator

//  insert your path here, or a file picker prompt

var theFile = new File('path/to/file/file_name.ai');

var openOpt = new OpenOptions();

//  get swatches

openOpt.openAs=LibraryType.SWATCHES;

open(theFile,null,openOpt);

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
Valorous Hero ,
Mar 10, 2017 Mar 10, 2017

Copy link to clipboard

Copied

They will not do what you want when you're opening as library. What you want to do is open the document and duplicate the swatches from one document to another.

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
Valorous Hero ,
Mar 10, 2017 Mar 10, 2017

Copy link to clipboard

Copied

Here is an example of basic process swatches, assuming you have two documents open, both having the same color space.

#target illustrator

function test(){

  var doc = app.activeDocument, doc2 = app.documents[1];

  alert(doc.name + " , " + doc2.name);

  var thisSw, newSw;

  for(var i=0; i<doc2.swatches.length; i++){

    thisSw = doc2.swatches;

    if(thisSw.name == "[Registration]" || thisSw.name == "[None]"){

      continue;

    }

    newSw = doc.swatches.add();

    newSw.name = thisSw.name;

    newSw.color = thisSw.color;

  }

 

};

test();

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
Explorer ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

Thanks, but it's actually not that i want to.

I need copy swatches not from another document, i need to copy them from library into document swatches.

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
Valorous Hero ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

Your library is just another .ai document, so are all the other libraries such as graphic styles or symbols. You'd have to open such a file with your script and copy the items over.

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
Explorer ,
Mar 16, 2017 Mar 16, 2017

Copy link to clipboard

Copied

LATEST

Silly-V, can u please correct code to open, work with and close document with swatches file by name, not by documents index?

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
Explorer ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

Now i understand, thanks a lot Silly-V!

I am not strong in coding, by this one is works right.

#target Illustrator

//  insert your path here, or a file picker prompt

var theFile = new File('C:/mySwatch.ai');

// var openOpt = new OpenOptions();

//  get swatches

// openOpt.openAs=LibraryType.SWATCHES;

open(theFile,null/*,*openOpt*/);

  var doc2 = app.activeDocument, doc = app.documents[1];

  var thisSw, newSw;

  for(var i=0; i<doc2.swatches.length; i++){

    thisSw = doc2.swatches;

    if(thisSw.name == "[Registration]" || thisSw.name == "[None]"){

      continue;

    }

    newSw = doc.swatches.add();

    newSw.name = thisSw.name;

    newSw.color = thisSw.color;

  };

doc2.close(SaveOptions.DONOTSAVECHANGES);

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