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

Script to change fill color based on excel data?

New Here ,
Dec 08, 2010 Dec 08, 2010

Hi.  I'm curious if there is a way to change the fill color of, say a rectangle, in Illustrator based on data in an excel spreadsheet (csv or whatever).  For example: say the data in the excel cell is 1 and that corresponds to the rectangle in Illustrator having a yellow fill...  Now say I update the data in the cell to 2 and save.  I run the script and it makes the box red.  Is that even remotely possible?  Thanks.

TOPICS
Scripting
2.9K
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 Expert ,
Dec 08, 2010 Dec 08, 2010

Hi, yes it's possible, I used VBA on Windows

Assuming you have an Illustrator file with 1 square, and 2 swatches named "yellow" and "red"

this is how I set up the excel file

colorIndex.PNG

type the formula in cell F2 as shown, make your color updates on cell E2

VBA code:

Sub recolorSquare()
    Dim iapp As New Illustrator.Application
    Dim idoc As Illustrator.Document
    Dim rect As Illustrator.PathItem
   
    Dim whatColor As String
   
    whatColor = range("F2")
   
    Set idoc = iapp.ActiveDocument
    Set rect = idoc.PathItems(1)
   
    rect.FillColor = idoc.Swatches(whatColor).Color
   
    Set rect = Nothing
    Set idoc = Nothing
    Set iapp = Nothing
End Sub

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
Guide ,
Dec 09, 2010 Dec 09, 2010

It is also possible to interact directly with some spredsheet data on the mac using AppleScript. Both FMP and Excel support AppleScript. If you were to use Adobe's ExtendScript then the data would need to be exported to delimited text file then read in… for use…

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 10, 2010 Dec 10, 2010
LATEST

Thanks so much!  Going to try this out!

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