welcome: please sign in
location: おりがみの添付ファイル:dxf2svg.py

添付ファイル 'dxf2svg.py'

ダウンロード

   1 # convert dxf(origamizer) to svg(inkscape)
   2 # (c) masahiko
   3 # date-written 2008-08-21
   4 
   5 import sys
   6 import string
   7 
   8 class point:
   9 	def __init__(self, xx, yy):
  10 		self.x = 100.0 * float(xx)
  11 		self.y = 100.0 * float(yy)
  12 	
  13 	def tostring(self):
  14 		s = ' %f %f' % (self.x, self.y)
  15 		return s
  16 
  17 def header():
  18 	return '''<?xml version="1.0" standalone="no"?>
  19 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
  20   "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
  21 <svg xmlns="http://www.w3.org/2000/svg"
  22      xmlns:xlink="http://www.w3.org/1999/xlink"
  23      width="400" height="400" viewBox="-200 -200 400 400">
  24   <title>svg sample</title>
  25 <defs>
  26 <style type="text/css"><![CDATA[
  27     .Paper { fill: none; stroke:#888888; }
  28     .Polygon { fill: #ffffdd; stroke:#aaaaaa; }
  29     .Mountain { fill: none; stroke:#ff0088; }
  30     .Valley { fill: none; stroke:#8800ff; }
  31     .CrimpMountain { fill: none; stroke:#ff8888; }
  32     .CrimpValley { fill: none; stroke:#8888ff; }
  33 ]]></style>
  34 </defs>
  35 '''
  36 
  37 def tail():
  38 	return '''</svg>
  39 '''
  40 
  41 def dxf2svg(name):
  42 	print 'convert', name, '.dxf to .svg ... ',
  43 	infile = open(name+'.dxf', 'r')
  44 	outfile = open(name+'.svg', 'w')
  45 	outfile.write( header() )
  46 	sw = 0
  47 	while 1:
  48 		temp = infile.readline()
  49 		if temp == '': break
  50 		if string.find(temp, 'POLYLINE') >= 0:
  51 			infile.readline() # 8
  52 			st = infile.readline() # name
  53 			p = []
  54 		elif string.find(temp, 'VERTEX') >= 0:
  55 			infile.readline() # 10
  56 			x = infile.readline()
  57 			infile.readline() # 20
  58 			y = infile.readline()
  59 			po = point(x, y)
  60 			p.append(po)
  61 		elif string.find(temp, 'SEQEND') >= 0:
  62 			outfile.write('<path class="' + st[:-1] + '" ')
  63 			sw = 0
  64 			for po in p:
  65 				if sw == 0:
  66 					outfile.write('d="M' + po.tostring())
  67 					sw = 1
  68 				else:
  69 					outfile.write('L' + po.tostring())
  70 			outfile.write(' Z" />\n')
  71 		elif string.find(temp, 'LINE') >= 0:
  72 			infile.readline() # 8
  73 			st = infile.readline() # name
  74 			infile.readline() # 62
  75 			infile.readline() # 1
  76 			infile.readline() # 10
  77 			x = infile.readline()
  78 			infile.readline() # 20
  79 			y = infile.readline()
  80 			p1 = point(x, y)
  81 			infile.readline() # 11
  82 			x = infile.readline()
  83 			infile.readline() # 21
  84 			y = infile.readline()
  85 			p2 = point(x, y)
  86 			outfile.write('<path class="' + st[:-1] + '" ')
  87 			outfile.write('d="M' + p1.tostring() + ' L' + p2.tostring() + '" />\n')
  88 	outfile.write( tail() )
  89 	infile.close()
  90 	outfile.close()
  91 	print 'done'
  92 
  93 # --- command
  94 
  95 if len(sys.argv) < 2:
  96 	print 'usage: python dxf2svg.py filename ...'
  97 else:
  98 	for name in sys.argv[1:]:
  99 		dxf2svg(name)

添付ファイル

添付ファイルを参照するには、(下のファイル一覧にあるように)attachment:filenameと記述します。 [get]リンクのURLは変更される可能性が高いので、利用しないでください。
 All files | Selected Files: delete move to page copy to page

ファイルを添付する権限がありません。