├── .gitignore
├── .project
├── .pydevproject
├── README.md
└── dxf2svg.py
/.gitignore:
--------------------------------------------------------------------------------
1 | *.py[cod]
2 | __pycache__
3 | *~
4 |
5 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | dxf2laser
4 |
5 |
6 |
7 |
8 |
9 | org.python.pydev.PyDevBuilder
10 |
11 |
12 |
13 |
14 |
15 | org.python.pydev.pythonNature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.pydevproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | /${PROJECT_DIR_NAME}
5 |
6 | python 3.0
7 | Default
8 |
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # dxf2svg
2 |
3 | Basic DXF to SVG converter.
4 |
5 | ## Usage
6 |
7 | The only non-standard dependency is `dxfgrabber`.
8 | If you dan't have it already, please install with
9 | your favourite package manager, e.g.
10 | ```
11 | pip install dxfgrabber
12 | ```
13 | When it's done, you should be able to do things like:
14 | ```
15 | python dxf2svg.py myDxfFile.dxf
16 | ```
17 | Please note that currently suported types are only `LINE`, `LWPOLYLINE`, `CIRCLE` and `ARC`.
18 | There is no support for block instances yet, though it should be quite easy to implement.
19 |
20 | ## TODO
21 |
22 | * Add support for other entity types.
23 | * Add support for block instances.
24 | * Add support for line thickness and color.
25 | * Add some example files.
26 |
27 |
--------------------------------------------------------------------------------
/dxf2svg.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import dxfgrabber
4 | import math
5 | import sys
6 | import os
7 |
8 | # SVG TEMPLATES
9 |
10 | # TODO: support arbitrary, user-specifiable units
11 | SVG_PREAMBLE = \
12 | '\n')
156 | #end: saveToSVG
157 |
158 | if __name__ == '__main__':
159 | # TODO: error handling
160 | if len(sys.argv) < 2:
161 | sys.exit('Usage: {0} file-name'.format(sys.argv[0]))
162 |
163 | for filename in sys.argv[1:]:
164 | # grab data from file
165 | dxfData = dxfgrabber.readfile(filename)
166 |
167 | # convert and save to svg
168 | svgName = '.'.join([os.path.splitext(filename)[0]] + ['svg'])
169 | if os.path.exists(svgName):
170 | if not raw_input("Overwrite existing file? (y/N) ").lower() == 'y':
171 | quit("Quitting.")
172 |
173 | svgFile = open(svgName, 'w')
174 |
175 | label_basename = os.path.basename(filename).split('_')[0]
176 | print("Opening '%s' (%s)" % (filename, label_basename))
177 |
178 | print "Saving to SVG file: {0}".format(svgName)
179 | saveToSVG(svgFile, dxfData)
180 |
181 | svgFile.close()
182 | #end: __main__
183 |
184 |
--------------------------------------------------------------------------------