Skip to main content
bryant51645657
Participant
Sep 13, 2018 6:35 PM UTC
Answered

Illustrator script: apply swatch from library

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 is closed to new replies. Start a new post to keep the conversation going.
Silly-V
Silly-VCorrect answer
Legend
Sep 13, 2018 7:36 PM UTC

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?

4 replies

CarlosCanto
Community Expert
Community Expert
Mar 19, 2020 7:36 AM UTC

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

Translate
Silly-V
Silly-VCorrect answer
Legend
Sep 13, 2018 7:36 PM UTC

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?

Translate
bryant51645657
Participant
Sep 13, 2018 9:37 PM UTC

That worked, thanks a lot!

Translate
Balav483
Known Participant
Mar 19, 2020 5:19 AM UTC

How to duplicate the swatches in script?

Translate