|
This project has been discontinued as I no longer have the license to use the necessary SDK. |
cad2svg is a simple Linux command-line utility that automatically converts AutoCAD files (both dwg and dxf) to SVG.
This utility works and has been tested on Linux. It should work on most x86 Linux distribution without change, and it would certainly not take too much to adapt it to Windows.
Capabilities
Since this is a command-line utility, it is perfect for batch jobs.
Capabilities:
- Output either compressed (
.sgvz) or standard (.svg) SVG (use the-zor--compressoption) - Quality of output is modifiable (use the
-gor--geometry WxHoption) - Supplied binary is standalone and does not depend on other installed libraries.
- Produced SVG is saved to
filename.svgor.svgzby default but can be saved to any file (use-oor--name outputfileoption) - Indicative performance (no formal tests were performed): it takes 2.2s to convert a 5.1MB dxf file into a compressed SVG file on an Athlon XP 1900 with 1GB of RAM. On more modern hardware this now takes a fraction of a second.
Limitations
Before you decide if this utility is right for you, note the following limitations:
- the produced SVG is a preview representation of the drawing: objects outlines are broken down into simple lines segments (polylines). This means that the produced graphic has lost all notion of the original cad objects (even curves are approximated into sets of line segments).
- Text is also broken down into a set of lines, so it is not searchable. There is also currently no link to external fonts, so there are all rendered into a default sans-serif font outline. Non-latin text strings are rendered as garbage. See cad2text for text extraction.
- There is a limit to the quality and precision of the output SVG: I wanted to do this to limit the size of the resulting file to the display size I was using, while still allowing a reasonable zoom factor for details. The advantage of this approach is that large AutoCAD files are converted into rather small SVG files. The drawback is that the resulting graphic is not very nice when zooming on details. The quality of the output is modifiable on the command line.
- Some objects may not be converted at all: bitmap graphics are ignored for instance.
- See the test sample below to check-out what works and what doesn't.
Please bear in mind that this utility is only meant to produce a preview of AutoCAD files. Do not depend on its output to be accurate enough to replace the original drawing in a decision process!
If you need a converter that does a better job, there is a commercial software available (no affiliation to me and I have not tested it): http://www.savagesoftware.com/
Example
This example is a converted test dwg file of 229KB converted to a 70KB compressed SVG (236KB uncompressed).
- Original DWG budweiser.dwg 229KB
- Uncompressed SVG budweiser.svg 236KB
- Compressed SVG budweiser.svgz 70KB
To view this svg file you will need Firefox or use a free Adobe or Corel plug-in.
Note that Firefox has native support for SVG but does not appear to support compressed SVGZ.
Why?
I needed a way to display AutoCAD files (both dwg and dxf files) on our intranet. This utility is part of a larger drawing management system that collects information from CAD files from our file servers and stores them in a database for easy search.
Installation
The download package contains both a pre-compiled binary for Linux RedHat/Fedora (that should work on any x86 Linux) and the source code.
If you encounter issues, please let me know.
It is important to note that this utility relies on the OpenDesign Alliance OpenDWG Toolkit and Viewkit libraries.
It is no longer free (US$250 first time/US$100 yearly renewal fee) to become a basic Associate Member and you need to sign an agreement and you cannot redistribute the library or use them in commercial products. This is why there is a pre-compiled version of cad2svg included: you can use this free software, but to compile it yourself, you'll need to obtain the library from the OpenDesign Alliance.
The pre-compiled package is a static binary, so there is no pre-requisite requirements to use it.
Compile
Do this only if you need to. Pre-requisites:
- binutils (they should be already installed, otherwise,
apt-get? install binutils) - gcc (any version less than 2 year old should work and should already be installed on your machine, otherwise,
apt-get? install gcc) - zlib (it is usually pre-packaged for each linux distribution. For RedHat for instance, you need to install the
zlib-devel-xxx.rpm packagewithapt-get? install zlib-devel)
I know it's bad, but there is no makefile for this. Once you have the necessary libraries from the OpenDWG kits, untar the provided cad2svg source and copy the following OpenDWG Linux files in your cad2svg directory:
ad2.a, ad2.had3.a, ad3.hadinit.a
We first need to transform the adinit.dat into an object file to be able to include it into our binary. This file contains initialisation code and data and must be included in your project for it to work:
objcopy -I binary -O elf32-i386 -B i386 adinit.dat adinit.a
Then just compile it all together:
gcc -Wall -o cad2svg cad2svg.c ad2.a ad3.a adinit.a -lm -lz --static
License
The source code provided is free to use and modify. If you modify the source code and others could benefit from your change, then I require that you send me back your modifications so I can integrate them in the next version.
The compiled application includes copyrighted software libraries from Open Design Alliance ("Aliance"). These libraries are subject to a membership agreement with the Alliance and are only licensed for use in Applications from members of the Alliance. www.opendesign.com.
You cannot redistribute the provided compiled version of the application, either as a standalone software or as part of a package, unless you have an adequate membership from the Open Design Alliance.
Download
- As of December 2012, I am no longer licensed to provide the freeware download.
Versions
- 1.2: 02DEC2010, added license changes required by Open Design Alliance.
- 1.1: 18JUL2008, added original file size to verbose option printout.
- 1.0: JAN 2004, Original
See also
thanks for the job. It is a pity that it is no longer free to associate to the OpenDesign Alliance, I would have liked to see the code 'under the hood'
I've been using this converter for a while, right now I'm using our own in-company developed converter that converts DWG to PDF using a more recent version of the OpenDWG Alliance library. Your tool works great, it's unfortunate it doesn't support newer versions of AutoCAD and it's unfortunate that the return code is incorrect when using --version or --help (also --version outputs way more than just a usable version number), but it's good enough for those old DWG files lying around.
To mycroes: I wish I had more time to update the tool. Maybe some day.
This tool is exactly what I need. However, it appears not to work in a 64-bit environment. cad2svg complains that it cannot open the file and exists... Any suggestions? Thanks, Erik
Not sure this is 64-bit related. I had the same problem too with Autocad 2004 and 2007 DWG files. With Autocad 2000 it worked, even on 64-bit. B.
Sorry, but Where can i get OpenDWG Linux files? In opendesign.com just some strange Teigha soft... Please, help! I cannot fnd them...
cad2svg only convert autocad dwg to svg ? is is possible to convert coreldraw dwg to svg using cad2svg ?
Hi Is this project still active ? Any chance to see Autocad 2004 and 2007 support coming soon ? Otherwise is there an alternative ? Thx