Dan's SvgPlotting Library

An artisan using a primitive rope-and-pulley XYZ linear axis motion system to cut a shape in a large piece of leather.

Convert curves from SVGs directly into physical, straight‑line plotting instructions and completely skip the idea of manual curve flattening!

 

Why keep fiddling with Inkscape?

If you use Inkscape or other popular SVG editors to prepare your output for plotters and physical work, you will already be familiar with resorting to multi‑step workflows, involving at least the following steps.

That’s time-consuming, a lot of extra effort, and potential for error, not to mention that if you make any updates or improvements to the original drawing and want to print again, you have to repeat the entire process.

 

The SvgPlotting Wheelhouse

With the SvgPlotting library, you can get the finished physical plotting data with a single call, and there is no need to create a sacrificial or un-editable version of your file. Just follow these easy steps.

When you initialize the SvgImageItem above, the library generates a sequence of straight-line segments, with embedded pen-up and pen-down instructions, ready for plotting.

Curves? Handled. Precision? You decide via the curveVertexCount parameter when initializing the object.

 

Quickstart

Following is a quick start example of using the SvgPlotter library.

using System;
using System.IO;

using Html;
using SvgPlotting;

namespace SvgPlottingDemo
{
 public class Program
 {
  public static void Main(string[] args)
  {
   string content = File.ReadAllText(@"C:\Temp\MySvg.svg");
   HtmlDocument doc = new HtmlDocument(content);
   PlotPointPenStatus pen = PlotPointPenStatus.None;
   SvgImageItem svg = new SvgImageItem(doc, 50);

   // Optionally add a trace listener to output library activities to console.
   Trace.Listeners.Add(new ConsoleTraceListener());

   foreach (PlotPointItem plotPointItem in svg.PlotPoints)
   {
    if (plotPointItem.PenStatus != pen)
    {
     Console.WriteLine($"Pen Status: {plotPointItem.PenStatus}");
     pen = plotPointItem.PenStatus;
    }
    switch (plotPointItem.PenStatus)
    {
     case PlotPointPenStatus.PenDown:
      Console.WriteLine($" Line To: {plotPointItem.Point}");
      break;
     case PlotPointPenStatus.PenUp:
      Console.WriteLine($" Move To: {plotPointItem.Point}");
      break;
    }
   }
  }
 }
}


From there, feed the paths into your plotter or convert to simple DXF, G‑code, HPGL, or whatever you need.

 

Features

Here are some of the main benefits of choosing the SvgPlotting library.

 

When to Use SvgPlotting

Here are only some of the scenarios in which the SvgPlotting library can come in handy.

 

Integration

This library is not only tiny but a lot of its value rests in that there are no commercial dependencies aside from Newtonsoft JSON.

 

Tips

Following are a few tips to help you get started.

 

Other Notes

This is an early release and there are currently a few limitations.