Mobile app version of vmapp.org
Login or Join
Angela777

: Applescript for Ai CS6, color set and get This is the last time I ask the question about Applescript - I see that this topic is unpopular since none of my questions has been answered. Probably

@Angela777

Posted in: #AdobeIllustrator #Cs6 #IllustratorScripting

This is the last time I ask the question about Applescript - I see that this topic is unpopular since none of my questions has been answered. Probably I'm on the wrong way, but scripting for Illustrator seems to be very interesting and useful.

I found the way to set the color of a layer to RGB color -

set color of current layer in current document to {red:45.0, green:34.0, blue:34.0}


however, when I immediately execute this line of code -

set currentColor to color of current layer in current document


In the RESULTS window I get long numbers like these -

{class:RGB color info, red:45.000001117587, green:34.000001773238, blue:34.000001773238}


Thus, I cannot perform comparing operation between the colors.

Any suggestions about color formatting, rounding the numbers/totals to the way I can compare current color with desirable one.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Angela777

2 Comments

Sorted by latest first Latest Oldest Best

 

@Angela777

I post the answer with the whole script, because Gramps asked for.
This script recolors the layer label color to provided RGB code - reddish

tell application "Adobe Illustrator"
set layersCounter to count layers in current document
display dialog "In current document there are " & layersCounter & " layers." & "Recolor layers label?"
repeat until (layersCounter = 0)
set color of layer layersCounter in current document to {red:255, blue:11, green:15}
set layersCounter to layersCounter - 1
end repeat
end tell

10% popularity Vote Up Vote Down


 

@Shanna688

So, in computer programming terms, the kind of numbers you have are called floating point numbers (sometimes they're called real numbers, too). The kind of number that you want is called an integer. To convert a floating point number to an integer, you need to use the magic phrase as integer when getting your number.

It works like this:

set currentColor to color of current layer in current document
set redValue to red of currentColor as integer


Now you should get 45 for your red, not 45.000001117587.

This tutorial gives more information about the various types of data in AppleScript.

P.S. – You might have better luck getting answers to programming questions at Stack Overflow

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme