Export SVG without dialog box

Hello!
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(“All”)
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.

https://mcneel.myjetbrains.com/youtrack/issue/RH-51260

– 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()
svgxml.Save(filename)
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.

Thanks,

-David

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:

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

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

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

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.

thanks,
c.

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,
c.

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

I am putting a fix for this into 8.2 which we should have another release candidate available for tomorrow.

1 Like

RH-78778 is fixed in Rhino 8 Service Release 2

2 Likes

Hi @stevebaer,

thank you for fixing above mentioned bug. It works in Rhino 8 SR2 now and i get the same amount of <path> nodes. The extra <g> nodes for layers and sublayers seems to be a new Rhino 8 feature which i can get rid of in the xml on my own to save the same output using Rhino 7 and 8.

I’ve found another issue which i don’t understand which applies to Rhino 7 and 8: The example curve below (a curve with degree 3) is captured as polyline using CaptureToSvg once opened in Illustrator. Is there a way to control this ?

ExampleCurve.3dm (61.0 KB)

One last question: When using CaptureToSvg with DrawSelectedObjectsOnly=True it seems the order of <path> nodes in the xml does not match the order of selected objects in Rhino. Does the exporter change the order ? If so, which order is used ?

thanks,
c.