Archive for the ‘SVG’ tag
Easy Processing > Illustrator Export (bonus SVG export)
After a long time playing with ideas for an easy Processing to Illustrator tool that would allow fancy coding to be piped directly into Illustrator for further layout (and was vector-based the whole way through – no terrible rasterization allowed), I now have a really easy solution that doesn’t involve any fancy code, external libraries, or command-line nonsense. The process:
1. Write your code as usual, but add PDF export
2. Run once and use File > Place… to insert the PDF into your AI document (do not simply open the document, as changes will not be reflected) — NOTE: be sure “Link” is clicked when placing
3. The resulting PDF, placed into the document as a single unit
4. Make changes in Processing and re-save the pdf – here we reduce the number of lines from 1,000 to 10
5. Back in AI, you will be prompted to update the pdf – easy! No need to ask it, simply moving between programs updates your work
6. Awesome, done.
A dead end for this process was SVG export from Processing, which is not super easy (surprisingly). Here’s my hack that uses Inkscape’s command line tools:
import processing.pdf.*;
String filename = "test.pdf";
boolean deletePDF = false;
void setup() {
size(11*72, 17*72);
// pretend we're creating a normal pdf
beginRecord(PDF, filename);
// do some stuff here!
for (int i=0; i<1000; i++) {
line(random(0,width), random(0,height), random(0,width), random(0,height));
}
endRecord();
// convert to svg
// via: http://www.inkscapeforum.com/viewtopic.php?f=5&t=5391
String[] outputFile = split(filename, '.');
runUnixCommand("/Applications/Inkscape.app/Contents/Resources/script --without-gui " + sketchPath + "/" + filename + " --export-plain-svg=" + sketchPath + "/" + outputFile[0] + ".svg", sketchPath);
// if specified, delete the original pdf
if (deletePDF) {
runUnixCommand("rm " + filename + " -f", sketchPath);
}
// X11 will still be running, so you'll have to quit it by hand...
}
void runUnixCommand(String commandToRun, String dir) {
File workingDir = new File(dir); // where to do it - should be full path
String returnedValues; // value to return any results
// run the command!
try {
Process p = Runtime.getRuntime().exec(commandToRun, null, workingDir);
int i = p.waitFor();
if (i == 0) {
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ( (returnedValues = stdInput.readLine ()) != null) {
println(returnedValues);
}
}
else {
BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ( (returnedValues = stdErr.readLine ()) != null) {
println(returnedValues);
}
}
}
catch (Exception e) {
println("Error running command!");
println(e);
}
}
SVG Interpolation in Processing

F > Q interpolated using SVG control points in Processing.






