Advertisement
Guest User

Untitled

a guest
Nov 9th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. # find and store LINE, ARC, CIRCLE entities into a list of dicts
  2. '''
  3. Line group codes
  4. Group codes Description
  5.  
  6. 100 Subclass marker (AcDbLine)
  7. 39 Thickness (optional; default = 0)
  8. 10 Start point (in WCS). DXF: X value; APP: 3D point
  9. 20, 30 DXF: Y and Z values of start point (in WCS)
  10. 11 End point (in WCS). DXF: X value; APP: 3D point
  11. 21, 31 DXF: Y and Z values of end point (in WCS)
  12. 210 Extrusion direction. (optional; default = 0, 0, 1). DXF: X value; APP: 3D vector
  13. 220, 230 DXF: Y and Z values of extrusion direction
  14.  
  15. Arc group codes
  16. Group codes Description
  17. 100 Subclass marker (AcDbCircle)
  18. 39 Thickness (optional; default = 0)
  19. 10 Center point (in OCS). DXF: X value; APP: 3D point
  20. 20, 30 DXF: Y and Z values of center point (in OCS)
  21. 40 Radius
  22. 100 Subclass marker (AcDbArc)
  23. 50 Start angle
  24. 51 End angle
  25. 210 Extrusion direction. (optional; default = 0, 0, 1). DXF: X value; APP: 3D vector
  26. 220, 230 DXF: Y and Z values of extrusion direction
  27.  
  28. Circle group codes
  29. Group codes Description
  30.  
  31. 100 Subclass marker (AcDbCircle)
  32. 39 Thickness (optional; default = 0)
  33. 10 Center point (in OCS). DXF: X value; APP: 3D point
  34. 20, 30 DXF: Y and Z values of center point (in OCS)
  35. 40 Radius
  36. 210 Extrusion direction. (optional; default = 0, 0, 1). DXF: X value; APP: 3D vector
  37. 220, 230 DXF: Y and Z values of extrusion direction
  38. '''
  39.  
  40. def readdxf(fn):
  41. startEntities = False
  42. startLine = False
  43. startArc = False
  44. startCircle = False
  45. storePoint = False
  46. entities = []
  47.  
  48. with open(fn, 'r') as f:
  49. for line in f:
  50. if line.strip() == 'ENTITIES':
  51. startEntities = True
  52.  
  53. if startEntities:
  54. if line.strip() == 'LINE':
  55. dd = dict.fromkeys(('10','20','30','11','21','31'), 0.0)
  56. dd['type'] = line.strip()
  57. startLine = True
  58.  
  59. if line.strip() == 'ARC':
  60. dd = dict.fromkeys(('10','20','30','40','50','51'), 0.0)
  61. dd['type'] = line.strip()
  62. startArc = True
  63.  
  64. if line.strip() == 'CIRCLE':
  65. dd = dict.fromkeys(('10','20','30','11','21','31'), 0.0)
  66. dd['type'] = line.strip()
  67. startCircle = True
  68.  
  69. if line.strip() == 'ENDSEC':
  70. startEntities = False
  71.  
  72. if startLine:
  73. if storePoint:
  74. dd[entity] = line.strip()
  75. storePoint = False
  76.  
  77. if line.strip() in dd:
  78. entity = line.strip()
  79. storePoint = True
  80.  
  81. if line == ' 0\r\n':
  82. startLine = False
  83. entities.append(dd)
  84.  
  85. if startArc:
  86. if storePoint:
  87. dd[entity] = line.strip()
  88. storePoint = False
  89.  
  90. if line.strip() in dd:
  91. entity = line.strip()
  92. storePoint = True
  93.  
  94. if line == ' 0\r\n':
  95. startArc = False
  96. entities.append(dd)
  97.  
  98. if startCircle:
  99. if storePoint:
  100. dd[entity] = line.strip()
  101. storePoint = False
  102.  
  103. if line.strip() in dd:
  104. entity = line.strip()
  105. storePoint = True
  106.  
  107. if line == ' 0\r\n':
  108. startCircle = False
  109. entities.append(dd)
  110.  
  111. return entities
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement