SVG output script

I have added a new flag to the export.svg operator to allow a render of a range of frames. I have also altered the final output filename to include the frame number that is was rendered on (thus algo_0001.svg instead of algo.svg). This way you can kick out an animated sequence of SVG files. My end goal is to then process that folder of SVG files, using Illustrator jasvascript, to convert them into a series of .ai files that After Effects can read.

If you are interested in rendering a SVG range, you can check out the attached BLEND file which has Liero’s altered script. The new ANIM button is highlighted in yellow.

Attachments


266_SVG_export_animation.blend (116 KB)

That’s really usefull, thanks Liero and Atom for this script.

good adition Atom! did a few tests and it seems to work fine… and you’re still trying to learn some spanish :stuck_out_tongue:

it is in the script now, also placed a size property -linked to render resolution- that will show in inkscape as the page… it proved useful on batch converting svgs to pngs

@Liero: I added one more little feature for my own personal use and thought I would offer it up to share. I pulled down your most recent version of the code and added a feature that generates an Adobe Javascript that can be executed by Illustrator CS3 to batch convert the SVG output into PDF format.

After you render, take a look at your output folder and there should be a file called cs3_illustrator_convert_SVG_to_PDF.jsx. Open up illustrator and execute the script under File\Scripts\Other (browse to script). The conversion can take some time, but you will see the script opening the SVG file and saving the PDF file. Once completed, re-visit your folder and it should now have PDF versions for each of the SVG files.

I realize this is not useful to Linux users, but if there are any Adobe users out there who want to get their SVG sequence into After Effects, this can little script can speed things up.

Here is the main def I added.


#Atom 02262013.
def writeAdobeJavascriptEntry(file_handle, source_filename):
    source_to_alter = source_filename.replace('\\','/')        # Adobe uses backwards slashes for pathing.
    file_handle.write("var svg_filename = \"%s\"
" % source_to_alter)
    file_name, file_extension = os.path.splitext(source_to_alter)
    target_filename = "%s.pdf" % file_name
    file_handle.write("var pdf_filename = \"%s\"
" % target_filename)
    file_handle.write("var options
")
    file_handle.write("var importFile = new File( svg_filename )
")
    file_handle.write("var outputFile = new File( pdf_filename )
")
    file_handle.write("docRef = app.open(importFile)
")
    file_handle.write("options = new PDFSaveOptions()
")
    file_handle.write("options.compatibility = PDFCompatibility.ACROBAT5
")
    file_handle.write("options.generateThumbnails = true
")
    file_handle.write("options.preserveEditability = true
")
    file_handle.write("docRef.saveAs( outputFile, options)
")
    file_handle.write("
")

Example JSX script output…


var svg_filename = "C:/tmp/algo_0088.svg"
var pdf_filename = "C:/tmp/algo_0088.pdf"
var options
var importFile = new File( svg_filename )
var outputFile = new File( pdf_filename )
docRef = app.open(importFile)
options = new PDFSaveOptions()
options.compatibility = PDFCompatibility.ACROBAT5
options.generateThumbnails = true
options.preserveEditability = true
docRef.saveAs( outputFile, options)

var svg_filename = "C:/tmp/algo_0089.svg"
var pdf_filename = "C:/tmp/algo_0089.pdf"
var options
var importFile = new File( svg_filename )
var outputFile = new File( pdf_filename )
docRef = app.open(importFile)
options = new PDFSaveOptions()
options.compatibility = PDFCompatibility.ACROBAT5
options.generateThumbnails = true
options.preserveEditability = true
docRef.saveAs( outputFile, options)

Attachments

266_SVG_export_animation.blend (120 KB)

@Liero: I have been playing with your script all day. Trying out the various settings. I thought I would try it out on a more complex scene so I pulled down Pumping Memory from Blendswap. I notice that the output does not see certain surfaces as solid. Are there settings to that will allow solid surfaces? Or is z-space always see-through?



My new favorite settings using Cometa from Blendswap. I altered the minimum slider value of Stroke Width to accept lower values (0.05 instead of 0.5). In this image I set stroke width to 0.15. This let me set a much thinner line. I have only Extended Edges enabled with a high Extend value of 5.0.


yes, it is not that easy, it first sort objects based on their origin, then sort faces based on centroid, then you can occlude strokes behind tris and quads… using the nearest point for sorting, and improving occlusion algorithm are in my list but as I’m flattening 3d objects they won’t always stack well… and i’m not a math wizard at all!

wasn’t aiming at something too complex, just a quick tool to then jump to Inkscape… and see Freestyle will be avaible in a few weeks! Freestyle works nicely with Python I believe

nice images by the way, last one ended up a bit creepy…
will at least add soflimits to those values that make sense

edit: also tried illustrator script it and went fine, from inkscape you can output pngs or pdfs too
there is a tool to help named ‘inkscapeBatch’

just updated file with minimal improvements -mainly a new stroke style-

@liero Freestyle is very nice and I am looking very much forward to see T.Ks awesome work in trunk yet it is not really suited for export to svg yet even though there is a script to do it. It is not very user friendly untill it is accessable in the user interface i think.

Great script! Can’t wait to try it out :slight_smile:
And cool collaboration work Atom!

I can’t seem to enable the addon in User Preferences, it just wont enable.
The console returns an error:

AttributeError: ‘_RestrictData’ object has no attribute ‘filepath’
(!) event has invalid window

can someone shine a light on this? im using blender 2.66

should work now, you’ll need to enter an absolute output path
it’s a very ‘experimental’ script, hope it helps in your job

Thanks man, i managed to make it work, turns out the script wasn’t finding a file called ‘algo_0001.svg’ in the tmp folder.

But i have another question.

I have a mesh, like this one:


And i want to achieve something like this, in vector graphics:


This was actually drawn by hand in Corel Draw, it’s simple lines with a thickness set.

I ask, can this be achieved with this script without having to clean the drawing in the end of the process? Maybe modifying it in some sort of way.

What about a more complex mesh? like this one:


yep my script is pretty dumb, you should keep an eye on freestyle… there should be an update for its SVG output script any of these days -maybe ask developer-

Allright, thanks again, i’ll keep an eye on it. And, no, your script is not dumb, it is awesome, it’s been most useful.

I need a svg exporter for bezier curves, because in my work we need to work with Corel Draw, and I need svg file to import in Corel Draw X6 and we will use it for plt files. I need SVG files was correct when I import it to Corel Draw X6, please help me!!!

Great script! Thank you very much Liero.

thanks bls!
senseku don’t think I can help you, see Freestyle svg output is working now

Senseku might be talking about what I proposed earlier on this thread. To export the Blender curves with same amount of knots and at the same position just as a 2d projection…?

ejnaren projecting seems to work fine with ortho camera only… perspective adds distortion
and bezier looks easy enough but no idea how to traslate more complex nurbs to svg :stuck_out_tongue:

Yeh I agree that it seems counterintuitive if the script distorts the path in perspective and with nurbs.

One solution would be to limit this functionality to beziersplines and ortho mode. Making it transparent so the if these two criteria are met it will project them directly as bezier -> svg. If not it will but in approximation points. Just to have the possibility is very cool.

Other solution is to find out if there is a clean way to predict the distortion and offset it but I have looked at that as well and while it is possible it seems quite complex. Does blender approximate with line segmets in viewport since it is able to draw beziers curves in perspective?

For those in crisis - script that export bezier curve into SVG file.
Just from time to time I need to export 2D curve from blender … and it seems to me it keeps control point even 3D curve and perspective.
Edit: works only for bezier curves, only geometry is exported

Blender 2.49
http://download.blender.org/release/

Script “Bezier export”
http://blender.howto.cz/blender-link…ezierExport.py

(Download blender 2.49, download script, open blender, open script in blender in blender’s text editor window, append your curve from 2.6x blend file, select curve and with mouse over text editor window Run script (Alt+P), save.)
Note: Curve is generated from active camera view.

Would be nice to have this script for 2.6x too :slight_smile:
(I’m not sure if it fits to liero extend his great add-on in this way …

1 Like