How we match two pathItems have same fillColor using Extendscript?

Explorer ,
Jan 19, 2021 Jan 19, 2021

Copy link to clipboard

Copied

Hi All,

 

I have two path items in a document and the CMYK color filled.

Now I need to match programmatically using if condition, that path item having with CMYK (c:100, m=0, y=100, k=0) values.

 

Kindly help me to achieve this using extendscript.

 

Thanks.

TOPICS
How to, Scripting

Views

82

Likes

translate

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 1 Correct Answer

Adobe Community Professional , Jan 19, 2021 Jan 19, 2021
This is a slow process if you have hundreds of paths, but essentially you can grab a fill color from a path with clr_1 = pathItem.fillColor and then compare clr_1.cyan != clr_2.cyan.However there can be javascript mathematical rounding artifacts which may put a decimal and a bunch of numbers afterwards - for this reason if it becomes an issue, you can use Math.round(clr_1.cyan) != Math.round(clr_2.cyan) and so on. When you compare all the 4 cmyk colors and all are true, you have the same color!

Likes

translate

Translate

Translate
Adobe Community Professional ,
Jan 19, 2021 Jan 19, 2021

Copy link to clipboard

Copied

This is a slow process if you have hundreds of paths, but essentially you can grab a fill color from a path with clr_1 = pathItem.fillColor and then compare clr_1.cyan != clr_2.cyan.
However there can be javascript mathematical rounding artifacts which may put a decimal and a bunch of numbers afterwards - for this reason if it becomes an issue, you can use Math.round(clr_1.cyan) != Math.round(clr_2.cyan) and so on. When you compare all the 4 cmyk colors and all are true, you have the same color!

Likes

translate

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 ,
Jan 19, 2021 Jan 19, 2021

Copy link to clipboard

Copied

Thank you so much for timely helps. It works.

Likes

translate

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