Export to SVG challenge

Thanks for uploading the 2 sample files, I noticed the lines in my version where missing, after some investigation I found I was using Line instead of line. Fusion read everything OK but it didn’t work in chrome.

I’ve updated the plugin also borrowed a line from your example so it scales to fit the browser window.

Here’s the output now, one tip run simplify on the curves first.
Karte - ExportSVG test2.svg.txt (109.4 KB)

And the Plugin
ExportSVG.rhp (23.5 KB)

2 Likes

Just FWIW, here is an example - my curve in green, yours in black. Zoom in on a high-curvature part.
curve test.svg.txt (5.6 KB)

Here is my code - it’s probably messy…
rh5.0 SVG 0.1.0004.rvb (14.4 KB)

2 Likes

That looks really good. I see that arcs stay arcs, and curves are approximated by line segments. In Inkscape the encircled CC is displayed warped, but in Xara it displays correctly.

Thanks for the suggestion! Admittedly I wasn’t aware of this very useful command, despite using Rhino for almost two decades now.

Curves look good in Inkscape, only some are missing, and one is in the wrong color. I assume you post processed the SVG manually?

How I did it in the end was to post process curves with ConvertToBeziers prior to exporting to .ai format, which I then converted to SVG using Xara Designer Pro X11:

beta_Karte.zip (20.4 KB)

Curves look fine to me, except for the small circle in front of Berlin. In the SVG it looks like a rounded square, but that may be a Xara issue.

There was no manual post-processing of the svg file, no. For reasons I don’t remember, my script tries to join curves together. Apparently sometimes this causes the joined curve to end up on a different layer.

That shows like that in Inkscape as well.

I’m talking about the conversion done with Xara. However, when I open the .ai-file in Rhino, then I see the same issue:

beta_Karte.zip (23.7 KB)

So it looks like a Rhino export bug.

Hello everybody,
here is my first program for Rhino. I did components for Grasshopper, but my last UI was with Borland C++. So I have still a lot to learn.
So here is an SVG exporter with a what you see is what you get. It is still a WIP but some advices could be interesting.
I use Rhinocommon with c#, XMLdocument to put the SVG in memory, Winform and SVG rendering library 2.2.1 for rendering SVG (NuGet Gallery | Svg 3.4.4).


Hope it will work on your computer and options are quite easy to understand.

  • At the moment everything is converted in mm (like linewidth unit). It is easy to change but I have a bug so I disable option.
  • Point could be filled but it doesn’t work with SVG renderer which use option of group rather than option on object) but works on Inkscape.
  • Text as SVG text is not at the good scale nor the good position, text as curve is OK
  • Hatch is copied to SVG
  • Annotation, texdot, dimensions are not copied
  • Nurbs are converted to Bezier
  • Circle to Circle
  • Layer have the same organisation as Rhino but rendering is inverse.
  • There is not the option button on savefile dialog
  • The zoom of SVG render and move is with text box. Not mouse yet !!

Hope it could help
I must put it on Github when I will understand how to do it !

5 Likes

I installed the rhp in Rhino 5 (and tried the WIP also) by dragging and dropping it into Rhino and then ran the SaveAsSVGCommand command but nothing happens. Are there any special steps I have to take to get it to start?

Excuse me it is not in a command it is in the menu
Save as or
Export selected
And thanks for your program I didn t exploit all of it
Best regards

Looks good, but why didn’t you just start a new thread?

That works, thanks!

Two immediate comments:

  • When in model space, perhaps saving things in layouts is not optimal. I understand that a SaveAs is just saving everything in the file to another file but it seems counter-productive for the SVG format. I suppose the easy way out for me is to use export selected… But still… :wink:
  • The file header is making Chrome not render the SVG but rather print the xml. It seems like it doesn’t like the width and height properties in the <svg xmnls=“http://www.w3.org/2000/svg” width="[X]" height="[Y]" viewBox="[…]> header line. Would throwing these out cause problems elsewhere? Inkscape seems to be reading both without problems…

Looks awesome!

Only, it doesn’t work for me (version 5, 64 bit, Windows 7):

Error writing file C:\Temp\Karte2.svg
Error saving file C:\Temp\Karte2.svg

How I installed the plugin:

  1. Extracted the zip file.

  2. Unblocked the .rhp and .dll files.

  3. Restarted Rhino.

  4. Dragged the .rhp file into Rhino.

I’m also running that combination. I’m on the latest version of SR13 of Rhino - which SR are you on?

Interesting. I’m on SR12, and if I check for updates online, I get: “Your installation is the newest available.”

See:

Thanks for the comments
I understand that you don’t want layer which are groups in SVG
For the header I will look at it. I found some errors I didn’t read carefully specification, hope it will work. Width and height are pixels for the output so I have to adapt that.

I will post in few days a new version not compiled in debug mode. I will change net framework to 4.5.2. Hope it will work better.

I implemented line command so on the next release it will work better

No, layers as groups in SVG is fine.

I am talking about layouts also being saved.
In this picture you see that the only geometry in model space are the circle, the rounded rectangle, a hatched rectangle, a polyline, and a text object. When you save as SVG, you also get what is on all layouts that are in the file - in this case a bunch of P&ID symbols on my “Symbols” layout. I was hoping that it could be that only geometry in the model space is saved.

Upgraded to SR13, and the plugin still fails. Complete log:

Loading Neon for Rhino, version Aug 23 2013  05:19:36
Loading Brazil 2.0 for Rhino 5.0 version Sep 20 2013 15:59:46
Loading Rhino Render, version 1.50, Sep 13 2016, 23:38:59
File "C:\Temp\Karte.3dm" successfully read
Command: _SaveAs
Error writing file C:\Temp\Karte.svg
Error saving file C:\Temp\Karte.svg

Here is an update,
with several corrections mainly on XML header some small errors with big effects :frowning:
Now it works on saveas menu, export selected menu and saveasSVG command.
Beware of line size, if unit is far from mm like m, km … lines appears on the windows but will be faint on SVG viewers.
@Win, For me export selected just work for selected objects.

If it works well for other people, I will post that on food4rhino.


3 Likes