: Import vector data into illustrator 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)
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>
More posts by @Jennifer810
3 Comments
Sorted by latest first Latest Oldest Best
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:
Adobe Illustrator CC 2014 Reference: VB Script
Other versions
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.
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:
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
Online postscript 2 reference
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:
DXF reference
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:
PDF 1.7 Reference, see the appendices for simple examples.
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.
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).
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.