adding XDATA to dxf files

435 views
Skip to first unread message

ohit...@mail.ru

unread,
Oct 21, 2016, 8:42:08 AM10/21/16
to python-ezdxf
Hi!
I need to add some xdata (hyperlinks) to acad entities.
code:
import ezdxf
from collections import namedtuple


dwg = ezdxf.new('AC1027')
ms = dwg.modelspace()

DXFTag = namedtuple('DXFTag', 'code value')

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

But when i added xdata to circle file stops to open in acad. I get an error:
Premature end of object 
invalid or incomplete DXF input -- drawing discarded. 
Press ENTER to continue

Without xdata file opens normally

Can anybody help me to decide this problem?

Manfred Moitzi

unread,
Oct 22, 2016, 12:13:37 AM10/22/16
to python-ezdxf
Hi!

AutoCAD 2015 crashed without an error message!

Solution: create an APP ID entry for "PE_URL"
import ezdxf
from ezdxf.lldxf.tags import DXFTag

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',
                 [
                     DXFTag(1000, 'tralivali.ru'),
                     DXFTag(1002, '{'),
                     DXFTag(1000, 'tralivali'),
                     DXFTag(1002, '{'),
                     DXFTag(1071, 1),
                     DXFTag(1002, '}'),
                     DXFTag(1002, '}')
                 ])
dwg.saveas('xdata.dxf')

This works with AutoCAD 2015, but I don't know how to test if AutoCAD recognized the XDATA.

Manfred Moitzi

unread,
Oct 22, 2016, 1:06:35 AM10/22/16
to python-ezdxf
UPDATE: ezdxf 0.7.7 - Entity.tags.new_xdata() and Entity.tags.set_xdata() accept tuples as tags, no import of DXFTag required

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')

Am Freitag, 21. Oktober 2016 14:42:08 UTC+2 schrieb ohit...@mail.ru:

ohit...@mail.ru

unread,
Oct 22, 2016, 11:32:46 AM10/22/16
to python-ezdxf
Updated to version 0.7.7 and tryed you solution and it works fine! (tested in Autocad Civil 3D 2014)
Didn't know that fist i neeed to add appip and then add xdata atached to it..
Thank you! Your module is great, now i'm free from autocad and can make drawings only with python (and your module of cource :) )! 

суббота, 22 октября 2016 г., 8:06:35 UTC+3 пользователь Manfred Moitzi написал:
Reply all
Reply to author
Forward
0 new messages