Export SVG without dialog box

I’m trying to write a script for the automatic export to SVG.
After the following combination of commands:

import rhinoscriptsyntax as rs
filename = “test”
rs.Command("_-Export " + filename + “.svg _Enter”)

the dialog box appears where you need to specify parameters such as size, view, scale, and so on.
How to make that without the dialog box? But with the following parameters:
Size: custom, 10x10 cm
Output Type: Vector output
Output Color: Print Color
View and Output Scale: Top, Extents

Hi @bobrovnich,

This is definitely a bug.


– Dale

Since you are using python, you should be able to do this using RhinoCommon

import Rhino
import scriptcontext as sc
import System.Drawing
import rhinoscriptsyntax as rs

dpi = 300
size = System.Drawing.Size(8.5*dpi,11*dpi)
settings = Rhino.Display.ViewCaptureSettings(sc.doc.Views.ActiveView, size, dpi)
svgxml = Rhino.Display.ViewCapture.CaptureToSvg(settings)

filename = rs.SaveFileName()
1 Like

Hi Bobrovnich, I’m running into the same problem while trying to export SVG. Did you manage to solve this? I am trying to initiate the export from grasshopper. I have very limited knowledge of scripting.



Hi @stevebaer,

i’ve been using your above code in Rhino 7 for a bunch of scripts and have a problem now using Rhino 8. In Rhino 7 it exported the svg file with a single <path> node for each curve object, eg exporting 2 curves resulted in:

   <path d="M...."/>
   <path d="M...."/>

Using Rhino 8 i now get this structure in the xml, again for 2 curves:

   <g id="Default">
       <path d="M...."/>
       <path d="M...."/>
       <path d="M...."/>
       <path d="M...."/>
       <path d="M...."/>

It seems that i get a a lot of extra path nodes, curves fall apart into pieces, polylines are broken into lines and everything seems to be grouped when opening the file in Illustrator. This is breaking a lot for me.

Two questions:

  1. How to get the old behaviour of CaptureToSvg as it has been in Rhino 7 ?

  2. I am modifying svgxml before saving it, eg. to add id attributes to each path node and other things. When i try to access the XmlDocument created by CaptureToSvg using any XPath language, it fails eg. try to access the <path> nodes like this:

print svgxml.SelectNodes("//path").Count

always returns 0. But the XPath syntax is correct. I would appreciate any help on this.


Can you send me the Rhino 7 model of the two curves that produce different output in V8? We can start from there to figure out what to do.

Hi @stevebaer, than you for the quick reply.

Below is the origin Rhino 7 file containing 4 curves. In Rhino 7 i get 4 <path> nodes in the svg file, they are ungrouped once imported into Illustrator. Doing the same capture in Rhino 8 i get 28 <path> nodes in the svg file nested under the new <g> node. This results into 28 curves in Illustrator. Grouped and nested under an extra layer…

I’ve zipped the files since svg did not upload: Example.zip (145.9 KB)


Thanks; I’ll take a look and try to see what is different