Blender+Freestyle export to SVG

Hello, I’ve been working on some code originally written by Jarno Leppänen to export from BLENDER + Freestyle to SVG files.
I’ve updated the code to work with new freestyle API introduced with blender 2.70, then I’ve refactored the code to use xml.etree for parsing and svg writing, adding animation rendering feature.
The result are 3 freestyle modules you can use in frestyle script mode inside blender, they are meant to output filled surfaces, dashed hidden edges and solid visible edges, and can be used separately or in a sequence.
You can render still images or animations, and for each frame you render in the SVG output file, once opened in Inkscape, you will find a separate Inkscape layer with separate sub-layers for fills, hidden and visible edges.
A simple example is included in the code repository.
The code is released under MIT license and is hosted on github, you can find it here:


the original Jarno repo is located here:

best to all, francesco


Thank you for your contribution. I will want to learn more and see some more examples.

really thanks… I will go to test this :smiley:

some tutorial or is easy to use??

best

Diego

thank you very much for this

Awesome!!!
…but I have some problem to use it (blender 270 macosx 10.6.8)
Why it does not work in script mode? where am I doing wrong?
http://www.pasteall.org/blend/27941

hi I test this in blender 2.7 windows 8 and work fine… but both side material using nodes is unable… can you help me with that?? thanks

the material translation to svg is still quite basic, Jarno had already introduced z-transparency support, but due to svg nature I think it is quite difficult to render complex materials.
BTW: I’ve been working on the introduction of animated SVG in output file, and the updated code will be on the repo soon.
You can find an animated svg example here:
http://www.hv-a.com/freestylesvg/test_freestyle.svg

tested you file: the problem is that before applying the python scripts as freestyle modules you have to load them as text blocks in blender text-editor window, and then you can choose them in the module selection directly. If you open the scripts from within the freestyle module window it won’t work

tested you file: the problem is that before applying the python scripts as freestyle modules you have to load them as text blocks in blender text-editor window, and then you can choose them in the module selection directly. If you open the scripts from within the freestyle module window it won’t work.

Correct workflow is this:

  • load the scripts you intend to use in text editor
  • go to ‘render’ panel and enable freestyle
  • go to ‘render layers’ panel and in freestyle section choose ‘python scripting mode’ as Control Mode
  • add the style modules you previously loaded, clicking ‘Add’ and choosing them in selection field clicking on the left icon (this way you pick the pre-loaded text blocks, if you click on the icon to open the script file here it won’t work). You can use as many style modules as you want, they get rendered in SVG in a sequence, so the first module you have will be the bottom layer in Inkscape
  • go to ‘render’ panel and choose render or animation. the SVG output will be written in the same directory where the .blend file is, so it’s a good idea to save your blend file before rendering

I’ve just added new animation code to the repository, hope you like it

ok tnx man!!! :slight_smile:
in win7_64bit works fine

amazing stuff!

Thanks for this. Really useful. Would be nice if it could be implemented in a way you could choose an output file.

Also it seems to export geometry that has been deleted. does it save stuff in a buffer or something? I rendered a file with suzanne with the advanced py file then deleted suzanne and rendered a cube with the fill py. the output svg contained both suzanne and the cube.

I’ll play a bit more, this could be an error in my work flow.

I think it is because if the svg file already exists it does not get overwritten, but the new rendering is merged into the existing file. It is due to the way we use the freestyle queue in script mode, I will look into this, but for now I suggest you should delete or rename the svg file if you have already rendered the same blend scene.

Yeah, its not a big deal. I think svg export is a really great feature for blender. It would be great if it made it into official builds.

Thanks a lot, Francesco! This is really very useful!
Uptil now I have been playing with freestyle only in parameter mode, so switching to py is a bit of a challenge.
Could you (or someone else) give me some pointers on how I could change linestyle and stuff in a py script like I can in parameter mode?
I am experimenting already but not very successful :wink:
Well, even with the simple line and fill style I like it a lot. So thanks again :slight_smile:

Hi!

Is there any way to make this script output edges marked as a freestyle edge? Or all edges that their adjacent faces have a certain angle? (like in the edge-split modifier)?

I’ve updated the scripts to new 2.72 API changes, it should work now.
can you check it out?

btw. in 2.73 is probably going to be integrated an SVG exporter addon for freestyle, meanwhile these scripts could still be useful.

Thanks for a great script ffantoni. Will it be your script that gets incorporated into Blender? It works fine for me but the output dimensions get changed. I am using blender to model shapes for cnc cutting machines that need coreldraw files to work. I export from blender to .svg (thanks to you!) and then import into coreldraw to save out the .cdr file. It’s a pain but it works except for the scaling issue. I apply scale and am printing at 100%. I can’t think of any other settings that might affect it. Any ideas would be gratefully accepted. Thanks again for the script.