Grasshopper

algorithmic modeling for Rhino

Rhino Standard Vector Graphics (SVG) File Exporter For Browsers

This is not a Grasshopper geometry exporter, but a Grasshopper-based Rhino SVG exporter.


SVG files are infinitely scaleable vector art files for web browsers. They are just text files meant to be human readable.

Rhino lacks an SVG exporter it seems since there's no way to define stroke and fill beyond linewidths and print colors and layer colors, well, that's fine with me to re-purpose those things and turn Rhino into an Illustrator-like layer and sublayer aware SVG editor.

In fact, Rhino screws up Illustrator exports to only do layer order in the sequence the layers were created instead of the arranged order you have manually created in the Layers palette, so I grab that info and use it correctly and this then becomes a reliable Illustrator exporter for Rhino too that let's you define lineweights and stroke/fill colors.

A Python script pulls curves and text from the Rhino document and exports an SVG file to the C: drive and Illustrator can then open the file with layers intact, albeit a little eccentrically since everything is placed in an Illustrator Layer01 for some reason, and for my part I've considered everything to be a level two sublayer, so simple layer items come inside of their own redundant sublayer. That keeps geometry out of parent layers in Illustrator though.

Alter this line to change the export location:

text_file = open("C:\Output.svg", "w")

Command-R to refresh your browser page for a real preview of the output after pushing my Recompute button or using Grasshopper F5 Recompute. You can toggle preview by double clicking a toggle button too.

Internally there's the ability to add your own SVG code differently for locked versus normal layers. Hidden layers don't export. Individually assigned print weights or print colors are ignored in favor of the layer settings. Since Python is readable by most of those familiar with basic web programming, the script can be readily altered to add styles and Javascript actions etc.

So stroke color is normal layer color, just as Rhino shows, whereas Print Color becomes fill color and Print Width (in millimeters) becomes stroke width.

It's 170 lines of code.

It requires the latest Human plug-in for the Grasshopper-created previews:

http://www.food4rhino.com/project/human?ufh

Python is here:

http://www.food4rhino.com/project/ghpython?ufh

Preview could possibly be improved by physically displacing objects in Z, but the plot order alone seems to handle fill just fine but I think Grasshopper adds different types of objects to the canvas all at once or something so the strokes can fail to be hidden behind other objects.

Views: 6524

Replies to This Discussion

Now also outputs text to Grasshopper, including color, size, location (point) and angle.

Attachments:

Hi Nik, nice work !!

Here also an old attempt to do the same using standard GH components.

It works with line, polyline, polygon, circle, curve (not too well), texts an there is a final composer.

>> http://www.co-de-it.com/wordpress/gh-to-svg.html

If it's useful to you feel free to use it since we don't have time to make a standard plugin of it and to mantain it updated.

Best, Andrea

Example of use of my script to access a nesting utility on the web:

http://www.grasshopper3d.com/forum/topics/close-the-surfaces-or-the...

Hello Nik I put an exporter for Rhino on the discourse

https://discourse.mcneel.com/t/export-to-svg-challenge/25618/14

I could do as you, using print color and layer color and many other things...

Comments  are welcome

Hello! Could you explain how to make this work and what do you mean by "Alter this line to change the export location: text_file = open("C:\Output.svg", "w")"?

I just managed this to GH.

Thanks!

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service