Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # find and store LINE, ARC, CIRCLE entities into a list of dicts
- '''
- Line group codes
- Group codes Description
- 100 Subclass marker (AcDbLine)
- 39 Thickness (optional; default = 0)
- 10 Start point (in WCS). DXF: X value; APP: 3D point
- 20, 30 DXF: Y and Z values of start point (in WCS)
- 11 End point (in WCS). DXF: X value; APP: 3D point
- 21, 31 DXF: Y and Z values of end point (in WCS)
- 210 Extrusion direction. (optional; default = 0, 0, 1). DXF: X value; APP: 3D vector
- 220, 230 DXF: Y and Z values of extrusion direction
- Arc group codes
- Group codes Description
- 100 Subclass marker (AcDbCircle)
- 39 Thickness (optional; default = 0)
- 10 Center point (in OCS). DXF: X value; APP: 3D point
- 20, 30 DXF: Y and Z values of center point (in OCS)
- 40 Radius
- 100 Subclass marker (AcDbArc)
- 50 Start angle
- 51 End angle
- 210 Extrusion direction. (optional; default = 0, 0, 1). DXF: X value; APP: 3D vector
- 220, 230 DXF: Y and Z values of extrusion direction
- Circle group codes
- Group codes Description
- 100 Subclass marker (AcDbCircle)
- 39 Thickness (optional; default = 0)
- 10 Center point (in OCS). DXF: X value; APP: 3D point
- 20, 30 DXF: Y and Z values of center point (in OCS)
- 40 Radius
- 210 Extrusion direction. (optional; default = 0, 0, 1). DXF: X value; APP: 3D vector
- 220, 230 DXF: Y and Z values of extrusion direction
- '''
- def readdxf(fn):
- startEntities = False
- startLine = False
- startArc = False
- startCircle = False
- storePoint = False
- entities = []
- with open(fn, 'r') as f:
- for line in f:
- if line.strip() == 'ENTITIES':
- startEntities = True
- if startEntities:
- if line.strip() == 'LINE':
- dd = dict.fromkeys(('10','20','30','11','21','31'), 0.0)
- dd['type'] = line.strip()
- startLine = True
- if line.strip() == 'ARC':
- dd = dict.fromkeys(('10','20','30','40','50','51'), 0.0)
- dd['type'] = line.strip()
- startArc = True
- if line.strip() == 'CIRCLE':
- dd = dict.fromkeys(('10','20','30','11','21','31'), 0.0)
- dd['type'] = line.strip()
- startCircle = True
- if line.strip() == 'ENDSEC':
- startEntities = False
- if startLine:
- if storePoint:
- dd[entity] = line.strip()
- storePoint = False
- if line.strip() in dd:
- entity = line.strip()
- storePoint = True
- if line == ' 0\r\n':
- startLine = False
- entities.append(dd)
- if startArc:
- if storePoint:
- dd[entity] = line.strip()
- storePoint = False
- if line.strip() in dd:
- entity = line.strip()
- storePoint = True
- if line == ' 0\r\n':
- startArc = False
- entities.append(dd)
- if startCircle:
- if storePoint:
- dd[entity] = line.strip()
- storePoint = False
- if line.strip() in dd:
- entity = line.strip()
- storePoint = True
- if line == ' 0\r\n':
- startCircle = False
- entities.append(dd)
- return entities
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement