QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Exporting a Drawing to SVG

SVG Export in QCAD is completely implemented in ECMAScript with one of the main classes being SvgExporterPG:

// include class SvgExporterPG:
include("scripts/Pro/ImportExport/SvgExporter/SvgExporterPG.js");

The export can be done through funciton 'exportFile':

var exporter = new SvgExporterPG(document, { "scale": "10:1"});
exporter.exportFile("example.svg");

Complete code:

// include class SvgExporterPG:
include("scripts/Pro/ImportExport/SvgExporter/SvgExporterPG.js");
// init application name:
qApp.applicationName = "MyApplication";
var storage = new RMemoryStorage();
var spatialIndex = new RSpatialIndexNavel();
var document = new RDocument(storage, spatialIndex);
document.setUnit(RS.Millimeter);
// create an operation:
var operation = new RAddObjectsOperation();
// corner point of the triangle::
var p1 = new RVector(0, 0);
var p2 = new RVector(10, 0);
var p3 = new RVector(5, Math.sin(RMath.deg2rad(60))*10);
// add line entity to operation:
operation.addObject(new RLineEntity(document, new RLineData(p1, p2)));
operation.addObject(new RLineEntity(document, new RLineData(p2, p3)));
operation.addObject(new RLineEntity(document, new RLineData(p3, p1)));
// apply operation to document:
operation.apply(document);
var exporter = new SvgExporterPG(document, { "scale": "10:1"});
exporter.exportFile("example.svg");