5

I have a program that generates thousands of vector points (just coordinates), the format is not fixed, but it could be something like this:

(2.4785|77.01)
(78.8|9.88)
(45.33|0.2)

I am able to format/convert this coordinates any way necessary.

My question is: How can I import these coordinate data into Illustrator as vector points, so I can work with them properly (give them a stroke, scale them etc.).

The result could be something like this, but this is pixel data. I want something similar to that, only as a vector.

Edit: Each coordinate should result in one dot/circle being rendered in Illustrator, so maybe each coordinate should be made into a line with identical beginning and end in illustrator?

It is a little hard to see in the screenshot, but the lines actually consist of many individual dots which are not always touching.

I generated the dot coordinates with a little java code, if anyone is interested in it, just PM me.

Solution: Jackson Hyde suggested SVG as a possible format in his answer, which turns out to work perfectly. I just generate this SVG file and then import it into Illustrator. There I can select all points and add a stroke and do some other fancy stuff.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events"
     version="1.1" baseProfile="full"
     width="20px" height="20px">

<line x1="15.23" y1="2.25" x2="15.23" y2="2.25" />
<line x1="8.1234" y1="7.85" x2="8.1234" y2="7.85" />
[...]

</svg>
6
  • 1
    Individual points imported into Illustrator would be fruitless since nothing would be rendered from them. So are all these points part of one big polyline? And if so are they already in the correct order?
    – JohnB
    Jun 23, 2014 at 12:55
  • They are not part of a line, they are individual points. So maybe each coordinate should be a line with identical start- and end-point in Illustrator, so they are rendered. Or is there a better way to render a dot who's size you can change later on?
    – Lars Ebert
    Jun 23, 2014 at 12:57
  • Hmm, as far as I know, a line with identical start and end points would still not be rendered. I think I would try placing a small ellipse centered on each point. You can then modify the styling in Illustrator. The way to go about this would be to work with SVG
    – JohnB
    Jun 23, 2014 at 13:03
  • I just checked. Having a line with the length zero and giving it a stroke and rounded ends results in a nice little round dot.
    – Lars Ebert
    Jun 23, 2014 at 13:06
  • 1
    Excellent, hadn't thought of that! Would you mind editing your question to mention the program your using to improve the search-ability for anyone else trying to do this?
    – JohnB
    Jun 23, 2014 at 13:08

3 Answers 3

7

As a alternate to SVG you could generate a EPS file instead, its less verbose than SVG and has less caveats. Here's a quick intro:

http://paulbourke.net/dataformats/postscript/

Generating EPS

EPS is a framed form of postscript meant to be included in other postscript jobs/desktop publishing applications. To handle this it needs a header to define the bounding box etc. The header would look as follows:

%!PS-Adobe-3.0 EPSF-3.0 
%%BoundingBox: 0 0 100 100
%%Title: Demo for GD.SE
%%Creator: Janne Ojala 
%%CreationDate:  2014-06-23
%%EndComments

This info is strictly not necessary for illustrator, as illustrator is a postscript engine. Nevertheless, you may want to include it so the file can be used as is without illustrator. Using a header also makes it easier to use in illustrator. The Bounding box defines the size of your artwork, coordinates lower left, upper right.

Next you need to handle your data for ease you may want to add a simple routine for drawing a single point:

/P {newpath 1 0 360 arc fill} def %draw circle with radius of 1

Now all you need is to define each point as follows:

15.23 2.25 P
8.1234 7.85 P
...

Finally your eps needs a end marker like this

%%EOF

Done. In general EPS is one of the easiest formats to generate, you could actually omit all the P calls by iterating over an array, file or binary data but ill leave this as it is for time being.

Workflow

Here is a trick that you can use for visualizing the data while your developing the EPS file. After all something can go wrong and its useful to have some feedback:

  • Place the EPS file in Illustrator

Now each time you edit the EPS file and jump back to illustrator it will ask you you want to update. If you click yes, you get instant feedback, and if you have an error you get a blank image. You can expand it when your ready.

Other resources

  1. Online postscript 2 reference
  2. Ghostscript a software postscript engine, for debugging, conversion to PDF etc.

Alternate functions in EPS

The function could be replaced by:

1 setlinecap
/P {newpath moveto 0 0 rlineto stroke} def

for the same kind of 0 size line approach. you can add a:

1 -1 scale 

and use negative bounding box for top left measurement directions.


Other formats

In addition to EPS and SVG another easy transfer format is DXF. The DXF spec can be found here:

PDF is also relatively easy to generate in this specific case. Tough the easiest way would be to distill the EPS with acrobat or ghost script. Generating the data tables and check-sums is a bit of extra work but other than that its almost as straightforward as generating a EPS file. PDF Spec can be found here:

A manually crafted pdf sample, this uses the same idea as described in the the EPS and SVG answers containing the 2 demo points. Search for % graphics here for the relevant section (if you paste this in a text file that has PDF set as extension it should just work).

The problem with PDF is is generating the lengths of the sections for the XREF table which is a bit painful to do by hand. This is why I avoid PDF in quick cases like this. Granted, adobe will ignore the tags if the PDF is just one page. So ignoring those you may generate a technically incorrect PDF file that still just works. Fun example exploiting this phenomena can be found here.

5
  • I guess this would work just as well. But as I am generating the file automatically and the needed syntax is quite straightforward, as you can see in my edited question.
    – Lars Ebert
    Jun 23, 2014 at 13:21
  • I did consider EPS but my lack of knowledge (compared to SVG anyway) prevented me from recommending it. It would definitely be worth seeing the example you mentioned, especially if future readers can't work with SVG. Jun 23, 2014 at 13:26
  • 2
    @LarsEbert EPS is much more straightforward to generate. And about 30 chars less data per point.
    – joojaa
    Jun 23, 2014 at 13:50
  • +1 for EPS efficiency - if you're working with any sort of XML based format, it probably won't be efficient! :) Jun 23, 2014 at 14:12
  • Thanks for the additional info. Now I am torn between this and Jacksons answer to accept. Is there any way to accept both, as they both work perfectly. SVG is more human-readable and EPS is more efficient.
    – Lars Ebert
    Jun 23, 2014 at 14:28
4

The easiest way I can think of is formatting your application to output an SVG Formatted Image. Illustrator can work with SVG graphics in a number of ways.

It's worth noting that in your image you are displaying more than just a cloud of points. It looks like your points have either been transformed over time (to give a 'trail' effect) or are connected to create paths. Just outputting a cloud of coordinates will not replicate this effect, you'll need to work with the SVG coordinate spec (coordinate transforms in particular).

2
  • The dots in the screenshot are procedurally generated by me, I can export the very same dot coordinates and import them in illustrator, so that should yield the same result, shouldn't it? I will try exporting the dots as SVG, thanks for the tip!
    – Lars Ebert
    Jun 23, 2014 at 13:04
  • 1
    Ah yes, on closer inspection I see your image is just point cloud data, apologies! Exporting your points as SVG and then importing that SVG into Illustrator should yield the same results. Jun 23, 2014 at 13:08
4

Since the data in this question is already available inside a program it may also make sense to use a programming interface this sidesteps the need of a file.

Programmatic access with COM

COM is a windows technology that allows nearly any programming language to directly interface with existing windows applications. Adobe calls this the VB API but it would work with only slight modifications in most general purpose languages like C, C++, Python etc. Its also built-in in .Net languages. For example a python source that uses comtypes module (for win32com alternative see here) would look as follows:

import comtypes.client

# following call is slow to instantiate the first 
# time you run it on a new machine as it builds the API
appObj = comtypes.client.CreateObject("Illustrator.Application")  
docObj = appObj.Documents.Add()
docObj.DefaultStrokeCap = 2 # round

POINTS = [
    (15.23, 2.25),
    (8.1234, 8.1234)
    #... or whatever database call you want
]

for point in POINTS:
    pathItem = docObj.PathItems.Add()
    pathItem.SetEntirePath( (point, point) )

That's it, use any language you wish, this saves you form dumping the data out to intermediary format. The API descriptions can be found at:

Benefits

  • No need for intermediate files
  • Can work inside your existing code base
  • You could insert symbols instead of points

Downsides

  • Only works on windows.
  • COM can be hard to learn at first, but well worth the effort.
  • Needs a copy of Illustrator on machine compared to say EPS.

Using Adobes javaScirpt engine

The same thing could be done with javaScript using the extensions by Adobe. The code would look as follows:

docObj = app.documents.add()
docObj.defaultStrokeCap = StrokeCap.ROUNDENDCAP

POINTS = Array(
        Array(15.23, 2.25),
        Array(8.1234, 8.1234)
    );

for (i in POINTS){
        pathItem = docObj.pathItems.add();
       pathItem.setEntirePath( Array(POINTS[i], POINTS[i]) );
}

Which is nearly identical to the python COM code.

Benefits

  • You could insert symbols instead of points
  • works on all platforms

Downsides

  • javaScript would still need the data somehow
  • Needs a copy of Illustrator on machine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.