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

Add black color to the color list - only if it does not exist in the color list

Explorer ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

 

Hello I am looking for a script that will add black color to the color list
) black = 100)


Only if it does not exist in the color list. not spot color!

TOPICS
Scripting

Views

102

Likes

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 , Jun 11, 2022 Jun 11, 2022

Hello,

You can try the following

var _doc = app.documents[0];
var _isBlackExists = false;
var _swatches = _doc.swatches;
for (var i = 0; i < _swatches.length; i++) {
    var _swatch = _swatches[i];
    if (_swatch.color.cyan == 0 && _swatch.color.yellow == 0 && _swatch.color.magenta == 0 && _swatch.color.black == 100) {
        _isBlackExists = true;
        break;
    } else if (_swatch.name.toLowerCase() == 'black') {
        _isBlackExists = true;
        break;
    }
}
if (!_isBlackExists) {
...

Likes

Translate

Translate
Community Expert , Jun 11, 2022 Jun 11, 2022

If you set this to false, then Balck color will always be created even if it exists

Likes

Translate

Translate
Community Expert ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

Hello,

You can try the following

var _doc = app.documents[0];
var _isBlackExists = false;
var _swatches = _doc.swatches;
for (var i = 0; i < _swatches.length; i++) {
    var _swatch = _swatches[i];
    if (_swatch.color.cyan == 0 && _swatch.color.yellow == 0 && _swatch.color.magenta == 0 && _swatch.color.black == 100) {
        _isBlackExists = true;
        break;
    } else if (_swatch.name.toLowerCase() == 'black') {
        _isBlackExists = true;
        break;
    }
}
if (!_isBlackExists) {
    var _blackSwatch = _doc.swatches.add();
    var _color = new CMYKColor();
    _color.cyan = 0;
    _color.yellow = 0;
    _color.magenta = 0;
    _color.black = 100;
    _blackSwatch.color = _color;
    _blackSwatch.name = 'Black';
}
Best regards

Likes

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 ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

Hey
That I changed to false
It works well. Thanks

Likes

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 ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

What you have changed to false? Please specify.

Best regards

Likes

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 ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

var _doc = app.documents[0];
var _isBlackExists = false;
var _swatches = _doc.swatches;
for (var i = 0; i < _swatches.length; i++) {
var _swatch = _swatches[i];
if (_swatch.color.cyan == 0 && _swatch.color.yellow == 0 && _swatch.color.magenta == 0 && _swatch.color.black == 100) {
_isBlackExists = false;
break;
} else if (_swatch.name.toLowerCase() == 'black') {
_isBlackExists = false;
break;
}
}
if (!_isBlackExists) {
var _blackSwatch = _doc.swatches.add();
var _color = new CMYKColor();
_color.cyan = 0;
_color.yellow = 0;
_color.magenta = 0;
_color.black = 100;
_blackSwatch.color = _color;
_blackSwatch.name = 'Black';
}

Likes

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 ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

LATEST

If you set this to false, then Balck color will always be created even if it exists

Best regards

Likes

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