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

[AS] Can't Find a CMYK Value Properly

New Here ,
Dec 11, 2008 Dec 11, 2008
I can't get Apple Script to recognize a CMYK color on a stroke. I'm trying to write a script that will step through page items in an AI file and, if it comes across items with certain CMYK values, change the values of those items.

But I'm coming across this weirdness:

If I get properties of an item, I can see that the color of a given stroke is:

stroke color:{class:CMYK color info, cyan:0.0, Zoom:100.0, yellow:100.0, black:0.0}

However, this following script does not successfully find the very same colored stroke even though the stroke color is exactly the same as that found when I used get preoperties. What's going on here. Is it a syntax error on my part or a bug?




tell application "Adobe Illustrator"
     tell current document
         tell layer 1
             set theList to every page item of it
             repeat with x from 1 to count of items in theList
                 repeat with k from 1 to count of theList
                     if stroke color of item k of theList = { class: CMYK color info, cyan:0.0, zoom:100.0, yellow:100.0, black:0.0} then
                         display dialog "hey"
                     end if
                 end repeat
         end tell
     end tell
end tell

TOPICS
Scripting
766
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
Adobe
Community Beginner ,
Dec 11, 2008 Dec 11, 2008
I've been writing AppleScripts for Illustrator since version 8 and have never seen "magenta" referred to as "zoom".

Something is weird with your installation/setup. It might be a terminology conflict with another scripting addition. Try removing all but the standard OSAX from your ScriptingAdditions folder(s) and restarting.

If that doesn't work, try a clean install of AI. If that doesn't work try logging in as a new user. And if that doesn't work, I'm all out of ideas.
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 ,
Dec 11, 2008 Dec 11, 2008
Chris, I don't know why you install is giving you the wrong info in the properties list. Sounds like something is wrong. The following will give you the items with the same stroke selected so you can work with them.

---------begin

tell application "Adobe Illustrator"
tell current document
tell layer 1
set theList to every page item of it
repeat with k from 1 to count of theList
if stroke color of item k of theList = {class:CMYK color info, cyan:0.0, magenta:100.0, yellow:100.0, black:0.0} then
set selected of item k of theList to true
--display dialog "hey"
end if
end repeat

end tell
end tell
end tell

--------end
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
New Here ,
Dec 11, 2008 Dec 11, 2008
Thanks Simon and Larry. The problem was one of my OSAXs. I removed my scripting additions and restarted and the mysterious "Zoom" is gone. We're back to magenta in the magenta slot.

Now the script works perfectly. Two follow-up questions though, if you have time:

1. I want to make sure where Larry was going with his setting "selected of item k" to true. It sounds like the plan is to iterate though all objects, select those that meet the criteria and then change that criteria (in this case a color property) once. Is this faster than a script that would find an object and change its color property before moving on and finding the next object? Is one way better than the other for any other reasons?

2. This one's tougher. I've noticed that if I create a CMYK swatch in AI and then apply that swatch to an object and then get properties of that object, the CMYK values of that object differ minutely from what I created. For example, if I create a C=10, M=20, Y=30, K=40 swatch and then get properties on an object I've applied it to, the color might actually be:
stroke color:{class:CMYK color info, cyan:10.000002384186, magenta:19.999998807907, yellow:30.000001192093, black:39.999997615814}

I guess this probably has something to do with color space or gamuts or something. But what I really want to know is can how I can test for a color that I think is 10/20/30/40 and find it even if it's really 10.000002384186/19.999998807907/30.000001192093/39.999997615814.

Is the only way to do this to get the color info for an item into a list or record and then round them to nearest 2-digit number or is there an easier way to handle this?

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 ,
Dec 11, 2008 Dec 11, 2008
LATEST
The way you suggest is probably faster. I was having trouble with your nested repeat. For the second question, it would probably work to use a named swatch and set the stroke color to that swatch which should cover the decimal string.
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