Eneroth SVG Exporter

Just published a quick little extension I made for my personal use. This one lets you export the selected entities as an SVG. Can be used for signage and other details on scale models, logos and more. Just make sure to orient your entities with the front side up.

This can also be used as a code examples for extension developers, showing concepts such as traversing/walking the model and resolving inherited material and visibility.

https://extensions.sketchup.com/extension/5da3501e-fefb-488f-98d5-8e28f2965593/eneroth-svg-exporter

14 Likes

Hello,

Thank you very much for this open source extension !

I’m searching a way to close the outlines, could you give me a little push?

outline

I think it’s here :

# Generate SVG path.
      #
      # @param face [Sketchup::Face]
      # @param transformation [Geom::Transformation] from local space to paper space.
      # @param color [Sketchup::Color]
      #
      # @return [String]
      def self.svg_path(face, transformation, color)
        d = face.outer_loop.vertices.map do |vertex|
          position = vertex.position.transform(transformation)
          "L #{format_length(position.x)} #{format_length(position.y)}"
        end.join(" ")
        # First "command" should be move to, not line to.
        d[0] = "M"

        # Inner loops, skip loops[0] as it is the outer loop.
        face.loops[1..-1].each do |loop|
          d_inner = loop.vertices.map do |vertex|
            position = vertex.position.transform(transformation)
            "L #{format_length(position.x)} #{format_length(position.y)}"
          end.join(" ")
          d_inner[0] = "M"
          d += d_inner
        end

I must add “L Xfirst_point Yfirst_point” at the end of the path. These values are the “M” values. Could you explain the syntax to do that. (I’m a newbie in Ruby for SU) ?
Best regards,
Renaud

OK, I found the solution. There is a closepath function in the SVG specification.

Here is the modification of the line 169 in the exporter.rb file :

"<path d=\"#{d} Z\" fill=\"#{format_color(color)}\" />\n"

Thank you again :smiley:

Should be a native import / export capability of SU and LO and a universal open source vector file format… but big thanks Christina for updating this capability for users :slight_smile:

1 Like

I think that line 169 should remain as is.

Line 155 should become …

   end.join(" ") << " Z"

… so that each loop tells the SVG path to close as it is processing faces (which are a set of closed edges.)

Then d_inner should begin with a space if there are inner loops, so line 165 should insert a leading space like:

     d_inner[0] = " M"

And again, each inner loop should close it’s corresponding SVG path, so line 164 should be:

     end.join(" ") << " Z"
1 Like

Good catch!

Got a new version submitted for review in Extension Warehouse. Should be available in a few business days. :+1:

1 Like

Do you know if there is a way to export non-closed edges ?
(It’s for laser engraving or laser cutting).

Anyway, thank you both of you.

It would be similar but the code would be iterating a curve object’s vertices and would not use the “Z” to close the path.

As of now the extension only export faces. It’s a very rough extension I made for a specific project more options are available if you do a native PDF export and convert to an SVG in a separate software.

OK, thanks !