Convert DXF to SVG without losing Custom Properties

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
klong28
Registered Member
Posts: 1
Joined: Tue Jul 07, 2015 7:25 pm

Convert DXF to SVG without losing Custom Properties

Post by klong28 » Tue Jul 07, 2015 8:10 pm

Hello

I am new to QCAD but quite optimistic about what it will allow me to do....

The end goal that I am trying to reach right now is being able to maintain, at minimum, an unique object identifier when I export to SVG (usually then used in Inkscape).

I currently have a DXF with many objects that have custom properties, but when exporting to svg none of these properties are maintained. I need someway to identify each specific graphic with external data, such as a name or number that will be included in the object properties in the SVG. Being able to bring any one of the custom properties from QCAD to an SVG would solve my problem. Even the Handle in QCAD does not seem to translate into svg.

My original plan when researching and deciding to purchase QCAD Pro was to make an add-on or modify the dxf2svg script to include this additional data, but according the this post.... viewtopic.php?f=33&t=3302&hilit=dwg2svg ....it sounds like those conversion scripts are not open source?

Can anyone recommend a way to maintain the identity of an object when converting from DXF to SVG? this would be a life saver!

Using QCAD Pro (3.9.4.0), currently working in Windows XP and 7 but could use Linux too.

Thanks!

User avatar
andrew
Site Admin
Posts: 9036
Joined: Fri Mar 30, 2007 6:07 am

Re: Convert DXF to SVG without losing Custom Properties

Post by andrew » Mon Jul 13, 2015 8:15 am

You can override SvgExporter or SvgExporterPG even if it's not available in source form:
include("scripts/Pro/ImportExport/SvgExporter/SvgExporterPG.js");

function MySvgExporter(document, properties) {
    SvgExporterPG.call(this, document, properties);
};

MySvgExporter.prototype = new SvgExporterPG();

MySvgExporter.prototype.exportAdditionalNamespaces = function() {
    // export additional namespaces here if appropriate:
    this.writeAttribute("xmlns:mynamespace", "http://mydomain.com/mynamespace");
};

MySvgExporter.prototype.exportAdditionalAttributes = function(entity) {
    if (isNull(entity)) {
        entity = this.getEntity();
    }
    if (isNull(entity)) {
        return;
    }

    this.stream.writeAttribute("mynamespace:handle", entity.getHandle());
};

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”