# SVG output script

**URL:** <https://blenderartists.org/t/svg-output-script/566412>\
**Category:** Released Add-ons and Extensions\
**Created:** [February 23, 2013, 9:51am UTC](https://blenderartists.org/t/svg-output-script/566412 "2013-02-23T09:51:37Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Atom](https://blenderartists.org/user_avatar/blenderartists.org/atom/32/2832_2.png) [@Atom](https://blenderartists.org/u/Atom)\
**Post date:** [February 25, 2013, 7:49am UTC](https://blenderartists.org/t/svg-output-script/566412/21 "2013-02-25T07:49:22Z")

</div>

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

 ![](https://blenderartists.org/uploads/default/original/3X/6/f/6f07f9e5c1b25315c181b65d53c694bb94e5bf98.jpg)  
[266\_SVG\_export\_animation.blend](https://blenderartists.org/uploads/default/original/3X/8/f/8fbfb02c0b6ea27a7c2a86e0c59feaf5967b8e1d.blend) (116 KB)

---

<div class="post-metadata">

**Author:** ![bupla](https://blenderartists.org/user_avatar/blenderartists.org/bupla/32/2743_2.png) [@bupla](https://blenderartists.org/u/bupla)\
**Post date:** [February 25, 2013, 8:22am UTC](https://blenderartists.org/t/svg-output-script/566412/22 "2013-02-25T08:22:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![liero](https://blenderartists.org/letter_avatar_proxy/v4/letter/l/53a042/32.png) [@liero](https://blenderartists.org/u/liero)\
**Post date:** [February 25, 2013, 6:29pm UTC](https://blenderartists.org/t/svg-output-script/566412/23 "2013-02-25T18:29:51Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Atom](https://blenderartists.org/user_avatar/blenderartists.org/atom/32/2832_2.png) [@Atom](https://blenderartists.org/u/Atom)\
**Post date:** [February 26, 2013, 7:42am UTC](https://blenderartists.org/t/svg-output-script/566412/24 "2013-02-26T07:42:31Z")

</div>

@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.

```auto

#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…

```auto

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](https://blenderartists.org/uploads/default/original/3X/0/0/00555b4124fd92ed5a3b6f3ba7b2910087c84917.blend) (120 KB)

---

<div class="post-metadata">

**Author:** ![Atom](https://blenderartists.org/user_avatar/blenderartists.org/atom/32/2832_2.png) [@Atom](https://blenderartists.org/u/Atom)\
**Post date:** [February 26, 2013, 1:23pm UTC](https://blenderartists.org/t/svg-output-script/566412/25 "2013-02-26T13:23:45Z")

</div>

@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_](http://www.blendswap.com/blends/view/66794) 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?

 ![](https://blenderartists.org/uploads/default/original/3X/f/8/f8552413d2fce92ea8670a2531b50eee91897b70.jpg)  

 ![](https://blenderartists.org/uploads/default/original/3X/b/9/b9de82e82e045c3f6031841d350d7d76378a7853.jpg)  

My new favorite settings using [Cometa from Blendswap](http://www.blendswap.com/blends/view/44100). 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.

 ![](https://blenderartists.org/uploads/default/original/3X/f/e/fefafa6598903dce375f29c590ef7b3e6b1a8caf.jpg)

---

<div class="post-metadata">

**Author:** ![liero](https://blenderartists.org/letter_avatar_proxy/v4/letter/l/53a042/32.png) [@liero](https://blenderartists.org/u/liero)\
**Post date:** [February 26, 2013, 3:06pm UTC](https://blenderartists.org/t/svg-output-script/566412/26 "2013-02-26T15:06:09Z")

</div>

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-

---

<div class="post-metadata">

**Author:** ![ejnaren](https://blenderartists.org/user_avatar/blenderartists.org/ejnaren/32/645982_2.png) [@ejnaren](https://blenderartists.org/u/ejnaren)\
**Post date:** [February 26, 2013, 3:13pm UTC](https://blenderartists.org/t/svg-output-script/566412/27 "2013-02-26T15:13:10Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![TheFinalCut](https://blenderartists.org/user_avatar/blenderartists.org/thefinalcut/32/20666_2.png) [@TheFinalCut](https://blenderartists.org/u/TheFinalCut)\
**Post date:** [March 1, 2013, 12:46am UTC](https://blenderartists.org/t/svg-output-script/566412/28 "2013-03-01T00:46:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Thales\_Kruger](https://blenderartists.org/letter_avatar_proxy/v4/letter/t/94ad74/32.png) [@Thales\_Kruger](https://blenderartists.org/u/Thales_Kruger)\
**Post date:** [April 16, 2013, 10:38am UTC](https://blenderartists.org/t/svg-output-script/566412/29 "2013-04-16T10:38:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![liero](https://blenderartists.org/letter_avatar_proxy/v4/letter/l/53a042/32.png) [@liero](https://blenderartists.org/u/liero)\
**Post date:** [April 16, 2013, 4:47pm UTC](https://blenderartists.org/t/svg-output-script/566412/30 "2013-04-16T16:47:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Thales\_Kruger](https://blenderartists.org/letter_avatar_proxy/v4/letter/t/94ad74/32.png) [@Thales\_Kruger](https://blenderartists.org/u/Thales_Kruger)\
**Post date:** [April 17, 2013, 3:53am UTC](https://blenderartists.org/t/svg-output-script/566412/31 "2013-04-17T03:53:51Z")

</div>

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:

 ![](https://blenderartists.org/uploads/default/original/3X/a/e/ae1bcee0ea5cb07603bcdfbe5af87dcb9746902b.jpg)  

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

 ![](https://blenderartists.org/uploads/default/original/3X/a/4/a4eb9cb7d4cc51c5c1c41a6b3383aa652b2ee31d.jpg)  

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:

 ![](https://blenderartists.org/uploads/default/original/3X/d/3/d37f7f5bc861605601729ad187208125923671ee.jpg)

---

<div class="post-metadata">

**Author:** ![liero](https://blenderartists.org/letter_avatar_proxy/v4/letter/l/53a042/32.png) [@liero](https://blenderartists.org/u/liero)\
**Post date:** [April 17, 2013, 8:48am UTC](https://blenderartists.org/t/svg-output-script/566412/32 "2013-04-17T08:48:23Z")

</div>

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-

---

<div class="post-metadata">

**Author:** ![Thales\_Kruger](https://blenderartists.org/letter_avatar_proxy/v4/letter/t/94ad74/32.png) [@Thales\_Kruger](https://blenderartists.org/u/Thales_Kruger)\
**Post date:** [April 17, 2013, 9:11am UTC](https://blenderartists.org/t/svg-output-script/566412/33 "2013-04-17T09:11:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sensenku](https://blenderartists.org/user_avatar/blenderartists.org/sensenku/32/18451_2.png) [@sensenku](https://blenderartists.org/u/sensenku)\
**Post date:** [April 26, 2013, 3:00pm UTC](https://blenderartists.org/t/svg-output-script/566412/34 "2013-04-26T15:00:57Z")

</div>

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!!!

---

<div class="post-metadata">

**Author:** ![bls](https://blenderartists.org/letter_avatar_proxy/v4/letter/b/e495f1/32.png) [@bls](https://blenderartists.org/u/bls)\
**Post date:** [April 27, 2013, 12:24am UTC](https://blenderartists.org/t/svg-output-script/566412/35 "2013-04-27T00:24:12Z")

</div>

Great script! Thank you very much Liero.

---

<div class="post-metadata">

**Author:** ![liero](https://blenderartists.org/letter_avatar_proxy/v4/letter/l/53a042/32.png) [@liero](https://blenderartists.org/u/liero)\
**Post date:** [April 30, 2013, 7:04am UTC](https://blenderartists.org/t/svg-output-script/566412/36 "2013-04-30T07:04:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ejnaren](https://blenderartists.org/user_avatar/blenderartists.org/ejnaren/32/645982_2.png) [@ejnaren](https://blenderartists.org/u/ejnaren)\
**Post date:** [April 30, 2013, 12:33pm UTC](https://blenderartists.org/t/svg-output-script/566412/37 "2013-04-30T12:33:04Z")

</div>

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…?

---

<div class="post-metadata">

**Author:** ![liero](https://blenderartists.org/letter_avatar_proxy/v4/letter/l/53a042/32.png) [@liero](https://blenderartists.org/u/liero)\
**Post date:** [April 30, 2013, 1:50pm UTC](https://blenderartists.org/t/svg-output-script/566412/38 "2013-04-30T13:50:26Z")

</div>

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 😛

---

<div class="post-metadata">

**Author:** ![ejnaren](https://blenderartists.org/user_avatar/blenderartists.org/ejnaren/32/645982_2.png) [@ejnaren](https://blenderartists.org/u/ejnaren)\
**Post date:** [April 30, 2013, 2:05pm UTC](https://blenderartists.org/t/svg-output-script/566412/39 "2013-04-30T14:05:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![vklidu](https://blenderartists.org/user_avatar/blenderartists.org/vklidu/32/4040_2.png) [@vklidu](https://blenderartists.org/u/vklidu)\
**Post date:** [May 29, 2013, 1:18am UTC](https://blenderartists.org/t/svg-output-script/566412/40 "2013-05-29T01:18:25Z")

</div>

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/](http://download.blender.org/release/)

Script “Bezier export”  
[http://blender.howto.cz/blender-link…ezierExport.py](http://blender.howto.cz/blender-links/Scripts_2.4x/BezierExport.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 🙂  
(I’m not sure if it fits to liero extend his great add-on in this way …

[Previous page](https://blenderartists.org/t/svg-output-script/566412.md?page=1)

[Next page](https://blenderartists.org/t/svg-output-script/566412.md?page=3)
