如何使用ezdxf向折线添加属性信息?

时间:2019-02-07 15:53:18

标签: python dxf

我正在使用 ezdxf软件包以写入dxf文件。我需要帮助存储折线的属性信息。为什么不能在布局/模型空间上使用add_attrib函数?下面是代码; dataObj是一个geojson字符串:

dwg = ezdxf.new('R2010')
flag = dwg.blocks.new(name='FLAG')
msp = dwg.modelspace()

#add attribute definitions
x = 0.5
y = -1
for i in Attribs:
    property = i;
    flag.add_attdef(str(property), (x, y), {'height': 0.5, 'color': 3})
    y = y-1.5

for i in range(numFeats):
    msp.add_polyline3d(dataObj[u'features'][i][u'geometry'][u'coordinates'])
    att_info_dict = dataObj[u'features'][i][u'properties']
    print dataObj[u'features'][i][u'geometry'][u'coordinates']
    print att_info_dict
    msp.add_attrib('DIAMETER',99,dataObj[u'features'][i][u'geometry'][u'coordinates'])

我收到的错误是:

Traceback (most recent call last):
  File "crtLine_wAttribs.py", line 46, in <module>
    msp.add_attrib('DIAMETER',99,dataObj[u'features'][i][u'geometry'][u'coordinates'])
  File "C:\Python27\ArcGIS10.6\lib\site-packages\ezdxf\graphicsfactory.py", line 116, in add_attrib
    return self.build_and_add_entity('ATTRIB', dxfattribs)
  File "C:\Python27\ArcGIS10.6\lib\site-packages\ezdxf\legacy\layouts.py", line 98, in build_and_add_entity
    entity = self.build_entity(type_, dxfattribs)
  File "C:\Python27\ArcGIS10.6\lib\site-packages\ezdxf\legacy\layouts.py", line 113, in build_entity
    entity = self._dxffactory.create_db_entry(type_, dxfattribs)
  File "C:\Python27\ArcGIS10.6\lib\site-packages\ezdxf\legacy\factory.py", line 109, in create_db_entry
    dbentry = self.new_entity(type_, handle, dxfattribs)
  File "C:\Python27\ArcGIS10.6\lib\site-packages\ezdxf\legacy\factory.py", line 82, in new_entity
    entity = wrapper_class.new(handle, dxfattribs, self.drawing)
  File "C:\Python27\ArcGIS10.6\lib\site-packages\ezdxf\dxfentity.py", line 85, in new
    entity.update_dxf_attribs(dxfattribs)
  File "C:\Python27\ArcGIS10.6\lib\site-packages\ezdxf\dxfentity.py", line 248, in update_dxf_attribs
    self.set_dxf_attrib(key, value)
  File "C:\Python27\ArcGIS10.6\lib\site-packages\ezdxf\dxfentity.py", line 185, in set_dxf_attrib
    dxfattr.set_attrib(self, key, value)
  File "C:\Python27\ArcGIS10.6\lib\site-packages\ezdxf\lldxf\attributes.py", line 168, in set_attrib
    self._set_extended_type(subclass_tags, value)
  File "C:\Python27\ArcGIS10.6\lib\site-packages\ezdxf\lldxf\attributes.py", line 182, in _set_extended_type
    raise DXFValueError('2 or 3 axis required')
ezdxf.lldxf.const.DXFValueError: 2 or 3 axis required

0 个答案:

没有答案