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

Set textframe fillcolor to the registration color

Contributor ,
Jan 30, 2023 Jan 30, 2023

Copy link to clipboard

Copied

Hi Community

 

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

 

AntonioPacheco_0-1675119497696.png

 

 

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

TOPICS
Bug , Scripting , Type

Views

429

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 2 Correct answers

Community Expert , Jan 30, 2023 Jan 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.
 * @Param {Document} doc - an Illustrator Document
 * @Returns {Swatch}
 */
function getRegistrationSwatch(doc) {

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

Votes

Translate

Translate
Contributor , Jan 31, 2023 Jan 31, 2023

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);

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 30, 2023 Jan 30, 2023

Copy link to clipboard

Copied

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.
 * @Param {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

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
Contributor ,
Jan 30, 2023 Jan 30, 2023

Copy link to clipboard

Copied

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

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
Contributor ,
Jan 31, 2023 Jan 31, 2023

Copy link to clipboard

Copied

@m1bgood morning!

I tried the following code just to see if I can get a response in return:

 

var doc = app.activeDocument;

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];

};

alert(getRegistrationSwatch(doc));

 

and I got this:

 

AntonioPacheco_0-1675172312532.png

Now in my code I try to do this:

var rect = doc.pathItems.rectangle(- y + h + space, x, w, h);
var text = doc.textFrames.areaText(rect);
text.contents = "SIZE: " + Math.round(anchoin * 100) / 100 + "'' W x " + Math.round(altoin * 100) / 100 + "'' H";
text.textRange.size = fontsize;
text.textRange.textFont = textFonts[font];
var regColor = getRegistrationSwatch(doc);
text.textRange.characterAttributes.fillColor = regColor;

 

According to the pretty well logic you did in the code I should get a textframe with fillcolor=registration... but I get the same error message.

 

AntonioPacheco_1-1675172562481.png

swatches looks like this:

 

AntonioPacheco_2-1675172577901.png

it's weird that this is happening, it should work 😕

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
Contributor ,
Jan 31, 2023 Jan 31, 2023

Copy link to clipboard

Copied

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);

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 ,
Jan 31, 2023 Jan 31, 2023

Copy link to clipboard

Copied

You've got it working (well done!!), but you changed the wrong part for good semantics. When you set a fillColor or strokeColor, it must be a Color object, not a Swatch object.

 

But the getRegistrationSwatch function I wrote returns a Swatch because that's is what is says it does. Once you have the registration Swatch you just ask for its color property, which will be a Color object. So I suggest you don't change the getRegistrationSwatch function, but instead use this:

 

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

 

 

It seems like a small point of order, but since a lot of programming is about knowing exactly what objects are working with, I think it is important.

- Mark 

 

P.S. Alternatively you could rename the function to getRegistrationColor. That would be fine, too, but not my preference because sometimes you want a Swatch.

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
Contributor ,
Jan 31, 2023 Jan 31, 2023

Copy link to clipboard

Copied

LATEST

Thank you so much! I'll change it like you said here.

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