瀏覽代碼

print text

beatescheibel 5 年之前
父節點
當前提交
a773e0bb21
共有 6 個文件被更改,包括 13962 次插入13927 次删除
  1. 1 1
      .idea/dxf_reader.iml
  2. 6 0
      .idea/encodings.xml
  3. 1 1
      .idea/misc.xml
  4. 13912 13912
      GV_12.DXF
  5. 20 13
      dxf_line_reader.py
  6. 22 0
      test2.py

+ 1 - 1
.idea/dxf_reader.iml

@@ -4,7 +4,7 @@
     <content url="file://$MODULE_DIR$">
       <excludeFolder url="file://$MODULE_DIR$/venv" />
     </content>
-    <orderEntry type="inheritedJdk" />
+    <orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" />
     <orderEntry type="sourceFolder" forTests="false" />
   </component>
   <component name="TestRunnerService">

+ 6 - 0
.idea/encodings.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding">
+    <file url="file://$PROJECT_DIR$/GV_12.DXF" charset="US-ASCII" />
+  </component>
+</project>

+ 1 - 1
.idea/misc.xml

@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
-  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (dxf_reader)" project-jdk-type="Python SDK" />
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
 </project>

File diff suppressed because it is too large
+ 13912 - 13912
GV_12.DXF


+ 20 - 13
dxf_line_reader.py

@@ -2,26 +2,33 @@
 def printpoint(b):
     print(b)
     obj = dict(zip(b[::2], b[1::2]))
-    if obj['100'] == 'AcDbMText':
-        print('{}'.format(obj['0']))
+    try:
+        if obj['100'] == 'AcDbMText':
+            print('{}'.format(obj['0']))
+    except:
+        pass
 
 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
+    #while line:
+        #line = fp.readline()
+    #line = line.rstrip()
+    print(line)
+    if line == '0':  # we've started a new section, so
+        print("Line {}: {}".format(cnt, line.strip()))
+            #try:
+            #    printpoint(buffer)  # handle the captured section
+            #except:
+            #    print("ERROR")
 
-        buffer = []  # and start a new one
-        buffer.append(line)
-        cnt += 1
+    #buffer = []  # and start a new one
+    #buffer.append(line)
+    cnt += 1
+f.close()
 
-
-printpoint(buffer)        # buffer left over from last pass through loop
+#printpoint(buffer)        # buffer left over from last pass through loop
 
 #https://leancrew.com/all-this/2016/12/dxf-data-extraction/

+ 22 - 0
test2.py

@@ -0,0 +1,22 @@
+def printsection(b):
+    print(b)
+    obj = dict(zip(b[::2], b[1::2]))
+    for keys, values in obj.items():
+        if keys == '1':
+            print(values)
+            print("\n")
+
+    #if obj.get('1'):
+    #    print('{}'.format(obj['1']))
+
+
+buffer = []
+file = open("GV_12.DXF", "r")
+for line in file:
+    line = line.strip()
+    #print(line)
+    if line == '100':         # we've started a new section, so
+        printsection(buffer)      # handle the captured section
+        buffer = []             # and start a new one
+    buffer.append(line)
+printsection(buffer)