Skip to main content
Known Participant
June 27, 2013
Answered

Create rectangles from info in excel file . . . Help!

  • June 27, 2013
  • 1 reply
  • 1922 views

I'm in need of help and have NO idea what I'm doing. I have an excel file with thousands of rows, each with a column for the x-coordinate, the y-coordiante, the height, and width of a rectangle. I need a script that will ask me to select the excel file, read the excel file, and create rectangles from each of the thousands of rows. I imagine this would be pretty simple for somebody who knows what they're doing, but I have no idea where to start. I'm working in a windows environment and have Illustrator CS4. Any suggestions? Any scripts out there that might give me a start?

This topic has been closed for replies.
Correct answer CarlosCanto

FYI, I'm on the east coast and have to get up early tomorrow (today), so please forgive me if I don't respond again until the morning. I really appreciate any suggestions you may have for me.


here you go, this is VBA code, I prefer to use it when I need to have Excel talk to Illustrator directly without exporting the Excel data.

to set up...

- Open Excel

- hit Alt+F11, to bring up the editor

- in the Tools menu, click on References...

- add a reference to "Adobe Illustrator CS5 Type Library" (or CS4 or your version)

- in the Personal.xls (or in any other book) add a Module. Personal is a global workbook that is always available. If you don't see it, go back to Excel and record a macro, anything will do. That will create the Personal file.

- and type the following in that module


Sub makeSquares()

    'carlos canto // 6/26/13

    'reads the active Excel workbook data to create squares in Illustrator

    'data is organized in rows as follows x, y, width, height

    'data has no headers, first row in cell "A1"

    Dim iapp As New Illustrator.Application

    Dim idoc As Illustrator.Document

    Dim isquare As Illustrator.PathItem

    Dim rowcount As Integer

    Dim x As Double

    Dim y As Double

    Dim w As Double

    Dim h As Double

    rowcount = Cells(1, 1).CurrentRegion.Rows.Count

    Set idoc = iapp.Documents.Add

    For i = 1 To rowcount

        x = Cells(i, 1)

        y = Cells(i, 2)

        w = Cells(i, 3)

        h = Cells(i, 4)

        Set isquare = idoc.PathItems.Rectangle(y, x, w, h)

    Next

    Set isquare = Nothing

    Set idoc = Nothing

    Set iapp = Nothing

End Sub

- save Personal book

- to run, move the cursor anywhere inside the Sub...End Sub and hit F5

for simplicity, start illustrator before running the script

1 reply

CarlosCanto
Community Expert
Community Expert
June 27, 2013

are you a programmer? just not familiar with illustrator, or not a programmer at all?

Known Participant
June 27, 2013

Not a programmer at all, sorry.

CarlosCanto
Community Expert
Community Expert
June 27, 2013

can you post a screen shot, showing how your data is laid out in excel?

mac or win?

edit:

I see you're on windows

Message was edited by: CarlosCanto