Applescript for Illustrator

Discussion in 'Design and Graphics' started by Baletin, Feb 14, 2014.

  1. Baletin macrumors member

    Joined:
    Apr 14, 2012
    #1
    Guys, I'm very confused :mad: because I cannot find any good sources about Applescript for Illustrator, especially up-to-date ones.

    If you know these - please write them here for me (the Adobe guides are very limited).

    I have a few questions, none of them has ever been answered on the forums I used to ask. Any suggestions will be greatly appreciated.

    1. Why this code

    Code:
    set color of current layer in current document to {red:45.0, green:34.0, blue:34.0}
    	set currentColor to color of current layer in current document
    gives in results (in editor) this line -
    {class:RGB color info, red:45.000001117587, green:34.000001773238, blue:34.000001773238}

    I cannot compare the colors this way, please, help...

    2. Any suggestions for programming "Divide objects below" function via applescript? I want to write a script to divide the artwork by a square (pattern creation).

    3. Any suggestions for deleting the pieces of artwork which left after "Divide objects below" beyond the cutting square (I mean how to delete them via applescript.

    Thank you friends...
     
  2. lucidmedia macrumors 6502a

    Joined:
    Oct 13, 2008
    Location:
    Wellington, New Zealand
    #2
    I think the challenge of finding good documentation is because Adobe has pushed hard to move everyone towards using Javascript as a scripting language...

    You would probably have a much easier time switching over to a more supported language with a larger pool of developers....

    http://www.adobe.com/devnet/illustrator/scripting.html
     
  3. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #3
    Hi,

    Other than the link above, I think your best bet is studying the scripting dictionary and googling for examples to learn from. Not ideal, I know. However, here are some general suggestions...

    Personally, I also find Script Debugger (http://www.latenightsw.com/sd4/) very helpful in figuring out why a script isn't doing what I think it should. It also lets you browse the object model which can be helpful.

    You may also find the AppleScript mailing list helpful: https://lists.apple.com/mailman/listinfo/applescript-users

    Good luck!
     
  4. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #4
    In relation to the colour comparison, I guess there's some kind of rounding going on behind the scenes or conversion between types. Whatever the case, it's a tiny difference in colour values. Why not just round the RGB values in each colour and compare those, as follows:


    Code:
    tell application "Adobe Illustrator"
    	tell front document
    		
    		--set up two colours
    		set colourOne to {class:RGB color info, red:45, green:34, blue:34}
    		set colourTwo to {class:RGB color info, red:45.7, green:34, blue:34}
    		
    		--compare colours
    		if my matchColours(colourOne, colourTwo) then
    			display dialog "Match"
    		else
    			display dialog "No match"
    		end if
    		
    		
    		
    	end tell
    end tell
    
    
    
    on matchColours(firstColour, secondColour)
    	--handler returns false if any RGB values don't match when rounded
    	tell application "Adobe Illustrator"
    		
    		if (round (red of firstColour)) is not (round (red of secondColour)) then return false
    		if (round (green of firstColour)) is not (round (green of secondColour)) then return false
    		if (round (blue of firstColour)) is not (round (blue of secondColour)) then return false
    		
    		return true
    		
    	end tell
    end matchColours
     

Share This Page