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

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

Explorer ,
Jun 11, 2022 Jun 11, 2022

 

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
496
Translate
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) {
...
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

Translate
Adobe
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) {
    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
Translate
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

Hey
That I changed to false
It works well. Thanks

Translate
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

What you have changed to false? Please specify.

Best regards
Translate
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

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';
}

Translate
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
LATEST

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

Best regards
Translate
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