Surely there is an easier way other than repeating through every group and/or character?
Is there a simple way to detect if all the fill and stroke colors within an Illustrator document are not “same”.
Or in other words, assume one did a “select all”. If either the Tool Bar’s “Fill” or “Stroke” icon contained a question mark then I would like to return a warning message.
Thank you Marc, I was sort of afraid of that. I figured I would post what I came up with that seems to do a fairly good job for basic files, not counting files with gradients, symbols, pattern swatches, gradient meshes, brushes, and other items I am not concerned with. For the most part, this “seems” to detect any differences with documents that contain paths and text.
--Here I am doing a color check.
tell application "Adobe Illustrator"
tell document 1
set hadFill to "No"
set hadStroke to "No"
--path items
try
set x to every path item
set fillPathColorTest to "null"
set myStop to "No"
repeat with i from 1 to count of every path item
--display dialog "doing this 2"
set fillPathColor to fill color of item i of x
set fillPathColor to fillPathColor as list
set fillPathColor to fillPathColor as text
if fillPathColor does not contain "gray color" and fillPathColorTest does not contain "null" and fillPathColor is not equal to fillPathColorTest then
display dialog "I am a different path fill color."
set myStop to "Yes"
exit repeat
end if
if fillPathColor does not contain "gray color" and fillPathColor does not contain "null" then
set fillPathColorTest to fillPathColor
set hadFill to "Yes"
end if
end repeat
end try
--Text items
try
set fillTextColorTest to "null"
repeat with x from 1 to count of text frames
if myStop contains "No" then
repeat with i from 1 to count of characters of text frame x
set fillTextColor to fill color of character i of text frame x
set fillTextColor to fillTextColor as list
set fillTextColor to fillTextColor as text
if fillPathColor is not equal to {} and fillTextColor is not equal to fillPathColor and fillPathColor does not contain "no" and fillPathColor does not contain "gray" then
display dialog "I am a different text fill color than a path fill zzzz."
set myStop to "Yes"
exit repeat
end if
if fillTextColor does not contain "gray color" and fillTextColorTest does not contain "null" and fillTextColor is not equal to fillTextColorTest then
display dialog "I am a different text fill color."
set myStop to "Yes"
exit repeat
end if
if fillTextColor does not contain "gray color" and fillTextColor does not contain "null" then
set fillTextColorTest to fillTextColor
end if
end repeat
end if
end repeat
end try
--stroke text items
try
set strokeTextColorTest to "null"
repeat with x from 1 to count of text frames
repeat with i from 1 to count of characters of text frame x
if myStop contains "No" then
set strokeTextColor to stroke color of character i of text frame x
set strokeTextColor to strokeTextColor as list
set strokeTextColor to strokeTextColor as text
if fillTextColor is not equal to {} and strokeTextColor is not equal to "no color info" and strokeTextColor is not equal to fillTextColor then
display dialog "I am a different text stroke color than the text fill color ."
set myStop to "Yes"
exit repeat
end if
if strokeTextColor does not contain "gray color" and strokeTextColorTest does not contain "null" and strokeTextColor is not equal to "no color info" and strokeTextColor is not equal to strokeTextColorTest then
display dialog "I am a different text stroke color."
set myStop to "Yes"
exit repeat
end if
if strokeTextColor does not contain "gray color" and strokeTextColor does not contain "null" then
set strokeTextColorTest to strokeTextColor
end if
end if
end repeat
end repeat
end try
--path stroke items
try
set x to every path item
set strokePathColorTest to "null"
repeat with i from 1 to count of every path item
if myStop contains "No" then
set strokePathColor to stroke color of item i of x
set strokePathColor to strokePathColor as list
set strokePathColor to strokePathColor as text
try
if strokePathColor does not contain "gray color" and strokePathColor does not contain "no" and strokePathColor is not equal to strokePathColorTest and strokePathColorTest is not equal to "null" then
display dialog "I am a different path stroke color z."
set myStop to "Yes"
exit repeat
end if
end try
if strokePathColor does not contain "gray color" and strokePathColor does not contain "no" then
try
set strokePathColorTest to strokePathColor
set hadStroke to "Yes"
if hadFill contains "Yes" then
if strokePathColorTest is not equal to fillPathColorTest then
display dialog "I was not the same stroke color as some other fill color"
set myStop to "Yes"
exit repeat
end if
end if
end try
end if
end if
end repeat
end try
--Text items
try
set fillTextColorTest to "null"
repeat with x from 1 to count of text frames
repeat with i from 1 to count of characters of text frame x
if myStop contains "No" then
set fillTextColor to fill color of character i of text frame x
set fillTextColor to fillTextColor as list
set fillTextColor to fillTextColor as text
if fillPathColor is not equal to {} and fillTextColor is not equal to fillPathColor and fillPathColor does not contain "no" and fillPathColor does not contain "gray" then
display dialog "I am a different text fill color than a path fill."
set myStop to "Yes"
exit repeat
end if
if fillTextColor does not contain "gray color" and fillTextColorTest does not contain "null" and fillTextColor does not contain "no" and fillTextColorTest is not equal to fillTextColorTest then
display dialog "I am a different text fill color."
set myStop to "Yes"
exit repeat
end if
if fillTextColor does not contain "gray color" and fillTextColor does not contain "null" then
set fillTextColorTest to fillTextColor
end if
try
if hadFill contains "Yes" then
if fillTextColorTest is not equal to fillTextColorTest then
display dialog "I was not the same text color as some other fill color"
set myStop to "Yes"
exit repeat
end if
end if
end try
try
if hadStroke contains "Yes" then
if strokePathColorTest is not equal to fillTextColorTest then
display dialog "I was not the same text color as some other stroke color"
set myStop to "Yes"
exit repeat
end if
end if
end try
end if
end repeat
end repeat
end try
end tell
end tell
i’m obviously unsure of what your main reason for wanting something like this so possibly could be simplifying
this too much so apologies in advance but do you need to check everything?
Can’t you just grab one item check its fill color say then check that against other items the instance you get an unmatch back then you’ve found your different item.
i know the below script is super simple but its only a brief example.
Sorry again if i’m way off.
tell application "Adobe Illustrator"
tell document 1
set x to fill color of path item 1
repeat with i from 2 to count of every path item
set y to fill color of path item i
if x is equal to y then
display dialog "Match"
else
display dialog "No Match"
end if
end repeat
end tell
end tell
My script is part of a much larger script. Our operators are selecting various typeset objects, often in combination with other shapes, i.e., rectangles, frames, within “InDesign”. Upon execute, the script copies their selection to a separate indd document, which then exports it to a PDF. It opens that PDF within Illustrator. All the appropriate text, strokes, fills, are applied a “Black Fill”” (prior to this color change is where I need my verification of like colors).
Final part of the script. the Illustrator file is placed within Photoshop file, trimmed and saved as a 1200 dpi Bitmap TIFF.
The intent is have a quick method to obtain a Bitmap TIFF (placed graphic file) from a logo typeset within InDesign. This graphic file serves its purpose within other products, layouts, etc.
There are situations when an operator selects a group of mixed colored objects/text. This defeats the purpose of the script, since the resulting file is a 100% black and white logo”technically no white.
Your snippet is very good. But I need to test beyond just paths. I need to compare all stroke colors, path fills, and text fill colors. It also needs to deploy logic to avoid/skip (no fills, empty paths) ,. I hope you understand where some complexity lies?
Nevertheless my final script works well. But it is cumbersome and lengthy. I was really hopping for a way to test for the “Tool Bar’s” current fill/stroke values after a “select-all” was executed within a document.
tell application "Adobe Illustrator"
tell document 1
set hadFill to "No"
set hadStroke to "No"
--path items
try
set x to every path item
set fillPathColorTest to "null"
set myStop to "No"
set myStopRaster to "No"
try
repeat with i from 1 to count of every path item
set myFill to class of fill color of path item i
set myFill to myFill as text
if myFill contains "gradient" then
set myStop to "Yes"
end if
end repeat
end try
repeat with i from 1 to count of every path item
set fillPathColor to fill color of item i of x
set fillPathColor to fillPathColor as list
set fillPathColor to fillPathColor as text
try
if ((count of raster items) is greater than 0 or (count of placed items) is greater than 0) then
set myStopRaster to "Yes"
end if
if ((count of non native items) is greater than 0) then
set myStop to "Yes"
end if
end try
if fillPathColor does not contain "gray color" and fillPathColorTest does not contain "null" and fillPathColor is not equal to fillPathColorTest then
set myStop to "Yes"
exit repeat
end if
if fillPathColor does not contain "gray color" and fillPathColor does not contain "null" then
set fillPathColorTest to fillPathColor
set hadFill to "Yes"
end if
end repeat
end try
--Text items
try
set fillTextColorTest to "null"
repeat with x from 1 to count of text frames
if myStop contains "No" then
repeat with i from 1 to count of characters of text frame x
set fillTextColor to fill color of character i of text frame x
set fillTextColor to fillTextColor as list
set fillTextColor to fillTextColor as text
if fillPathColor is not equal to {} and fillTextColor is not equal to fillPathColor and fillPathColor does not contain "no" and fillPathColor does not contain "gray" then
set myStop to "Yes"
exit repeat
end if
if fillTextColor does not contain "gray color" and fillTextColorTest does not contain "null" and fillTextColor is not equal to fillTextColorTest then
set myStop to "Yes"
exit repeat
end if
if fillTextColor does not contain "gray color" and fillTextColor does not contain "null" then
set fillTextColorTest to fillTextColor
end if
end repeat
end if
end repeat
end try
--stroke text items
try
set strokeTextColorTest to "null"
repeat with x from 1 to count of text frames
repeat with i from 1 to count of characters of text frame x
if myStop contains "No" then
set strokeTextColor to stroke color of character i of text frame x
set strokeTextColor to strokeTextColor as list
set strokeTextColor to strokeTextColor as text
--display dialog strokeTextColor as string
if fillTextColor is not equal to {} and strokeTextColor is not equal to "no color info" and strokeTextColor is not equal to fillTextColor then
set myStop to "Yes"
exit repeat
end if
if strokeTextColor does not contain "gray color" and strokeTextColorTest does not contain "null" and strokeTextColor is not equal to "no color info" and strokeTextColor is not equal to strokeTextColorTest then
set myStop to "Yes"
exit repeat
end if
if strokeTextColor does not contain "gray color" and strokeTextColor does not contain "null" then
set strokeTextColorTest to strokeTextColor
end if
end if
end repeat
end repeat
end try
--path stroke items
try
set x to every path item
set strokePathColorTest to "null"
repeat with i from 1 to count of every path item
if myStop contains "No" then
set strokePathColor to stroke color of item i of x
set strokePathColor to strokePathColor as list
set strokePathColor to strokePathColor as text
try
if strokePathColor does not contain "gray color" and strokePathColor does not contain "no" and strokePathColor is not equal to strokePathColorTest and strokePathColorTest is not equal to "null" then
set myStop to "Yes"
exit repeat
end if
end try
if strokePathColor does not contain "gray color" and strokePathColor does not contain "no" then
try
set strokePathColorTest to strokePathColor
set hadStroke to "Yes"
if hadFill contains "Yes" then
if strokePathColorTest is not equal to fillPathColorTest then
set myStop to "Yes"
exit repeat
end if
end if
end try
end if
end if
end repeat
end try
--Text items
try
set fillTextColorTest to "null"
repeat with x from 1 to count of text frames
repeat with i from 1 to count of characters of text frame x
if myStop contains "No" then
set fillTextColor to fill color of character i of text frame x
set fillTextColor to fillTextColor as list
set fillTextColor to fillTextColor as text
--display dialog fillPathColor as string
if fillPathColor is not equal to {} and fillTextColor is not equal to fillPathColor and fillPathColor does not contain "no" and fillPathColor does not contain "gray" then
set myStop to "Yes"
exit repeat
end if
if fillTextColor does not contain "gray color" and fillTextColorTest does not contain "null" and fillTextColor does not contain "no" and fillTextColorTest is not equal to fillTextColorTest then
set myStop to "Yes"
exit repeat
end if
if fillTextColor does not contain "gray color" and fillTextColor does not contain "null" then
set fillTextColorTest to fillTextColor
end if
try
if hadFill contains "Yes" then
if fillTextColorTest is not equal to fillTextColorTest then
set myStop to "Yes"
exit repeat
end if
end if
end try
try
if hadStroke contains "Yes" then
if strokePathColorTest is not equal to fillTextColorTest then
set myStop to "Yes"
exit repeat
end if
end if
end try
end if
end repeat
end repeat
end try
end tell
end tell
if myStop contains "Yes" then
tell application "SystemUIServer"
activate
set userResponse2 to display dialog "Cannot proceed in making this a Bitmap TIFF because more than one unique color was applied to either a fill, stroke, or text color. Please fix the logo and run the script again if you wish this to be a Bitmap TIFF file." buttons {"Stop"} default button "Stop" with icon stop
if button returned of userResponse2 contains "Stop" then
return
end if
end tell
end if
if myStopRaster contains "Yes" then
tell application "SystemUIServer"
activate
set userResponse2 to display dialog "Cannot proceed in making this a Bitmap TIFF because an image of some sort was found in this file. This script is intended for basic text and line items." buttons {"Stop"} default button "Stop" with icon stop
if button returned of userResponse2 contains "Stop" then
return
end if
end tell
end if
Jeff, not a solution but questions about the workflow. You are wanting to get PDF from ID to PS but make sure it’s 100k or 0k. To be converted to bitmap 50/50 dither split or other but test for other colour influence? Can’t you just count the top and bottom items of a histogram in Photoshop to see if anything is in between? If first + last = pixel count without anti-alias would that not do? Another option is to save and parse the AI file colours are stored in a postscript comment block. regardless of where they are applied. Me thinks this is easier and faster to find than open and loop all the page items. I may have overlooked something but a clearer idea of your intent and I ‘may’ know an alternative solution.
Glad i covered myself with not having a clue about what your trying to achieve
Was just trying to simplify your big script really but sometimes there isn’t an easy option.
However while saying that i have an idea but not sure if it will work, you say you want to check by selecting all
and checking for the question marks in the tool bar then couldn’t you check for the documents default fill or stroke colour.
tell application "Adobe Illustrator"
set x to default fill color of document 1
end tell
I suspect if there is a question mark in there after you select all then the script will error which you could catch in
an error handler of some sort.
Whereas if there is a color in there then it will return it.
Wow Mark, I would have never thought about that approach. Yes, that would work. I could have it throw an error based on the histogram variance. And if “good-to-go”, I could then have it apply a layer “color overlay” layer style using “black”. This would ensure that any pure white logos are converted to black, as opposed to using any level type adjustments to covert the file to black (which I do not believe would work)”prior to the 50/50 Bitmap conversion.
However, I do prefer the checking in Illustrator because what I did not mention is that the operator does have the ability to fix any issue at the Illustrator stage and then save an AI file if that is what they realize should be done if the multiple colors are necessary for aesthetic reasons. Not to mention, moving the file into Photoshop to then discover the error does add a little time in the process. These aren’t very complex files, so the cycling through paths in Illustrator is very fast.
But I am certain I will use your approach in other scripts.
Pidge, you weren’t far off. and as always I am very grateful for you responding. As for the default fill/stroke. Upon further review, there will be times when a path may have, i.e., a CMYK value for its stroke yet no fill, whereas other items may have the same CMYK value for its fill, yet no stroke. This would yield a question mark for both fill and stroke when all is selected, but it would not be an unacceptable file. So my initial explanation and request to test was incorrect. so please don’t kill me for my original request, and I hope you don’t refrain from helping me in the future
Jeff, if I was just checking to see if an *ai file was just grayscale and contained no colour info. I would parse either of these. Both of these should cover the whole file printing content grads and all that other stuff.
or in the standard AI comment block as this cut down example.
%!PS-Adobe-3.0
%%Creator: Adobe Illustrator(R) 15.0
%%AI8_CreatorVersion: 15.0.2
– a bunch of other file info here
%%HiResBoundingBox: 1.32764 -539.167 569.167 -60.1665
– ditto here
%%DocumentProcessColors: Cyan Black
%%CMYKProcessColor: 1 1 1 1 ([Registration])
– ditto here
%%EndComments
Very interesting Mark, This is something I have never even dabbled into”and it’s probably way over my head. For example, what is a practical example of how to obtain this XML info within AS then capture its results into a variable and later do something with that variable? It’s obvious something I would have to research. I only get to script about once a month. and when I do it’s sporadic throughout the day type things, trying to balance it with meetings and other crap. Really is a bummer because I would love to devote my entire days to learning more.
One last note. Keep in mind that in my instances the exported PDF being brought into Illustrator could be various colors. the catch is they need all be the same color for each stroke, fill, text.