Skip to main content
Inspiring
January 30, 2023
Answered

Set textframe fillcolor to the registration color

  • January 30, 2023
  • 1 reply
  • 832 views

Hi Community

 

I am trying to get my textframes into the registration color form my swatches, but VS shows me this messages:

 

 

 

I already tried:

text.textRange.characterAttributes.fillColor = doc.swatches[1].color;

text.textRange.characterAttributes.fillColor = doc.swatches['[Registration]'].color;

text.textRange.fillColor = doc.swatches[1].color;

text.textRange.fillColor = doc.swatches['[Registration]'].color;

 

The image above is just to show how I tried to look for an alert msg and what does it gets but shows error.

can anybody help me? Thank you

Correct answer AntonioPacheco

I did it! I just changed somethign in your function, this line:

return doc.swatches[i];

to this:

return doc.swatches[i].color;

Then, in the code I did:

text.textRange.characterAttributes.fillColor = getRegistrationSwatch(doc);

1 reply

m1b
Community Expert
Community Expert
January 30, 2023

I'm not sure why the code in your screen shot is getting that error. Perhaps the document has the registration swatch named differently (different locales name is differently). Try this function and see if it works:

var doc = app.activeDocument;
var regColor = getRegistrationSwatch(doc);


/**
 * Returns the document's Registration swatch.
 * @9397041 {Document} doc - an Illustrator Document
 * @Returns {Swatch}
 */
function getRegistrationSwatch(doc) {

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

        if (
            doc.swatches[i].color.typename == 'SpotColor'
            && doc.swatches[i].color.spot.colorType == ColorModel.REGISTRATION
        )
            return doc.swatches[i];

};

- Mark

Inspiring
January 31, 2023

Pretty sure it says registration, BUT of course I will try this code! I triedusing another colors (not index 0 which is none nor index 1 which is registration) and it worked on those ones, thank you so much let me test tomorrow