Skip to content

Commit

Permalink
new_xdata() and set_xdata() accept tuples as tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Manfred Moitzi committed Oct 22, 2016
1 parent bd2a229 commit 92280e5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
3 changes: 2 additions & 1 deletion NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
News
====

Version 0.7.7 - ...
Version 0.7.7 - 2016-10-22

* NEW: repairs malformed Leica Disto DXF R12 files, ezdxf saves a valid DXF R12 file.
* NEW: added Layout.unlink(entity) method: unlinks an entity from layout but does not delete entity from the drawing database.
* NEW: added Drawing.add_xref_def(filename, name) for adding external reference definitions
* CHANGE: renamed parameters for EdgePath.add_ellipse() - major_axis_vector -> major_axis; minor_axis_length -> ratio
to be consistent to the ELLIPSE entity
* UPDATE: Entity.tags.new_xdata() and Entity.tags.set_xdata() accept tuples as tags, no import of DXFTag required
* UPDATE: EntityQuery to support both 'single' and "double" quoted strings - Harrison Katz <harrison@neadwerx.com>
* improved DXF R13/R14 compatibility

Expand Down
21 changes: 21 additions & 0 deletions docs/source/howto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,24 @@ between DXF entities, this simplifies the navigation between the DXF entities.

.. important:: This does not render the graphical content of the DXF file to a HTML canvas element.

Adding New XDATA to Entity
--------------------------

Adding XDATA as list of tuples (group code, value)::

dwg.appids.new('YOUR_APP_NAME') # IMPORTANT: create an APP ID entry

circle = modelspace.add_circle((10, 10), 100)
circle.tags.new_xdata('YOUR_APP_NAME',
[
(1000, 'your_web_link.org'),
(1002, '{'),
(1000, 'some text'),
(1002, '{'),
(1071, 1),
(1002, '}'),
(1002, '}')
])

For group code meaning see DXF reference section `DXF Group Codes in Numerical Order Reference`, valid group codes are
in the range 1000 - 1071.
4 changes: 2 additions & 2 deletions ezdxf/lldxf/classifiedtags.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def get_xdata(self, appid):

def set_xdata(self, appid, tags):
xdata = self.get_xdata(appid)
xdata[1:] = tags
xdata[1:] = (DXFTag(t[0], t[1]) for t in tags)

def new_xdata(self, appid, tags=None):
"""Append a new xdata block.
Expand All @@ -171,7 +171,7 @@ def new_xdata(self, appid, tags=None):
"""
xtags = Tags([DXFTag(XDATA_MARKER, appid)])
if tags is not None:
xtags.extend(tags)
xtags.extend(DXFTag(t[0], t[1]) for t in tags)
self.xdata.append(xtags)
return xtags

Expand Down
23 changes: 23 additions & 0 deletions issues/20161021 adding xdata error/add_xdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import ezdxf

dwg = ezdxf.new('AC1027')
dwg.appids.new('PE_URL') # create APP ID entry
ms = dwg.modelspace()

c = ms.add_circle((10, 10), 100)
c.tags.new_xdata('PE_URL',
[
(1000, 'tralivali.ru'),
(1002, '{'),
(1000, 'tralivali'),
(1002, '{'),
(1071, 1),
(1002, '}'),
(1002, '}')
])
dwg.saveas('xdata.dxf')

## Error message:
## Premature end of object
## invalid or incomplete DXF input -- drawing discarded.
## Press ENTER to continue
13 changes: 9 additions & 4 deletions tests/test_classifiedtags.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,20 @@ def test_xdata3_tags(self):
self.assertEqual(xdata[3], (1070, 3))

def test_new_data(self):
self.tags.new_xdata('NEWXDATA')
self.tags.new_xdata('NEWXDATA', [(1000, 'TEXT')])
self.assertTrue(self.tags.has_xdata('NEWXDATA'))

xdata = self.tags.get_xdata('NEWXDATA')
self.assertEqual(xdata[0], (1001, 'NEWXDATA'))
self.assertEqual(xdata[1], (1000, 'TEXT'))

def test_set_new_data(self):
self.tags.new_xdata('NEWXDATA', tags=[DXFTag(1000, "Extended Data String")])
self.tags.new_xdata('NEWXDATA', tags=[(1000, "Extended Data String")])
self.assertTrue(self.tags.has_xdata('NEWXDATA'))

xdata = self.tags.get_xdata('NEWXDATA')
self.assertEqual(DXFTag(1001, 'NEWXDATA'), xdata[0])
self.assertEqual(DXFTag(1000, "Extended Data String"), xdata[1])
self.assertEqual((1001, 'NEWXDATA'), xdata[0])
self.assertEqual((1000, "Extended Data String"), xdata[1])

def test_append_xdata(self):
xdata = self.tags.get_xdata('MOZMAN')
Expand Down

0 comments on commit 92280e5

Please sign in to comment.