瀏覽代碼

added new files

bscheibel 5 年之前
父節點
當前提交
247c3a5639
共有 2 個文件被更改,包括 31 次插入3 次删除
  1. 27 0
      dxf_line_reader.py
  2. 4 3
      dxf_reader.py

+ 27 - 0
dxf_line_reader.py

@@ -0,0 +1,27 @@
+
+def printpoint(b):
+    print(b)
+    obj = dict(zip(b[::2], b[1::2]))
+    if obj['100'] == 'AcDbMText':
+        print('{}'.format(obj['0']))
+
+buffer = ['0', 'fake']
+filepath = 'GV_12.DXF'
+with open(filepath,'r', errors="replace") as fp:
+    line = fp.readline()
+    cnt = 1
+    while line:
+        line = fp.readline()
+        line = line.rstrip()
+        if line == '0':  # we've started a new section, so
+            print("Line {}: {}".format(cnt, line.strip()))
+            printpoint(buffer)  # handle the captured section
+
+        buffer = []  # and start a new one
+        buffer.append(line)
+        cnt += 1
+
+
+printpoint(buffer)        # buffer left over from last pass through loop
+
+#https://leancrew.com/all-this/2016/12/dxf-data-extraction/

+ 4 - 3
dxf_reader.py

@@ -1,18 +1,19 @@
 #!/usr/bin/env python
 
-from fileinput import input
+#from fileinput \
+import fileinput
 
 
 def printpoint(b):
     print(b)
     obj = dict(zip(b[::2], b[1::2]))
     if obj['0'] == 'AcDbMText':
-        print('{}'.format(obj['100']))
+        print('{}'.format(obj['0']))
 
 
 print('Code','Text')# header line
 buffer = ['0', 'fake']    # give first pass through loop something to process
-for line in input("GV_12.DXF"):
+for line in fileinput.input("GV_12.DXF", errors="replace"):
     line = line.rstrip()
     print(line)
     if line == '0':         # we've started a new section, so