Skip to main content
bryant51645657
New Participant
September 13, 2018
Answered

Illustrator script: apply swatch from library

  • September 13, 2018
  • 2 replies
  • 3069 views

Hi,

I'm working on a script to apply a swatch from a library to a pathItem and the color name to a textFrame.

It works, the problem is it crashes when I close the file with the PMS Library. Any help would be very appreciated.

Here is my code.

#target Illustrator

var docRef = app.activeDocument;

var docRef1 = app.open(File("~/Documents/PMSLibrary.ai"));

  // Get specific swatch

  var PMSColor = docRef1.swatches.getByName('PANTONE 100 C');

  // Add Swatch to Original Document

  var AddColor = docRef.swatches.add();

  AddColor.name = PMSColor.name;

  AddColor.color = PMSColor.color

  // Add text frame and pathItem

  var ColorFrame = docRef.textFrames.add('Color')

  var ColorBox = docRef.pathItems.add('Box')

  // Assign to Text Frame

  ColorFrame.contents = PMSColor.name

  // Assign color to PathItem

  ColorBox.fillColor = PMSColor.color

  // Close reference document

  docRef1.close(SaveOptions.DONOTSAVECHANGES);

  app.redraw();;

Thanks!

This topic has been closed for replies.
Correct answer Silly-V

try to apply the color to a temp path item, which you can then duplicate into your other document. Then close the library doc and see if it still crashes?

2 replies

CarlosCanto
Brainiac
March 19, 2020

1. get a ref of the swatch you want to duplicate

2. add a new swatch

3. apply ref swatch color in step 1 to new swatch

Silly-V
Silly-VCorrect answer
Brainiac
September 13, 2018

try to apply the color to a temp path item, which you can then duplicate into your other document. Then close the library doc and see if it still crashes?

bryant51645657
New Participant
September 13, 2018

That worked, thanks a lot!

Balav483
Known Participant
March 19, 2020

How to duplicate the swatches in script?