Can merge dxf with ezdxf

762 views
Skip to first unread message

Kordexa Stroken

unread,
Jan 22, 2018, 3:15:58 PM1/22/18
to python-ezdxf
Hello Everybody,

I want to merge 2 dxf files.Is there any way make with ezdxf 

best regards

Manfred Moitzi

unread,
Jan 22, 2018, 11:58:13 PM1/22/18
to Kordexa Stroken, python-ezdxf
Hi!

Yes, but it is complicated ;)

ezdxf can not import DXF R12 into later DXF versions and vice versa. Works best if both
drawings have the same DXF version or the target has a later version than the source 
drawing. ezdxf imports tables, blocks and the entities section.

source_dwg = ezdxf.readfile('source.dxf')
target_dwg = ezdxf.readfile('target.dxf')
importer = ezdxf.Importer(source_dwg, target_dwg)
importer.import_all()
# for drawings without block references:
# importer.import_tables()
# importer.import_modelspace_entities()
target_dwg.saveas('merged.dxf')

# check drawing, but works just in the upcoming version v0.8.5
if ezdxf.version < (0, 8, 5):
    exit()
auditor = target_dwg.auditor()
errors = auditor.run()
if len(errors) == 0:
    print('Import OK.')
else:
    print('Import maybe failed.')

Because of the complex internal references in DXF files, importing is not a good idea and will not work often. ezdxf is not a CAD application!

BTW: The importer is an old module and not often used by myself, so strange things may be happen.

Best regards,
Manfred



--
You received this message because you are subscribed to the Google Groups "python-ezdxf" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-ezdxf+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kordexa Stroken

unread,
Jan 23, 2018, 2:13:57 PM1/23/18
to python-ezdxf
Hi,

Thanks for your reply.This is option enough for me.I will test it 

Best Regards



23 Ocak 2018 Salı 06:58:13 UTC+2 tarihinde Manfred Moitzi yazdı:
To unsubscribe from this group and stop receiving emails from it, send an email to python-ezdxf...@googlegroups.com.

Yuxiang Song

unread,
Jan 18, 2019, 8:38:55 AM1/18/19
to python-ezdxf
Hi, 
It doesn't work for me.
Here is my code: 
source_dwg = ezdxf.readfile("source.dxf")
target_dwg = ezdxf.new(source_dwg.dxfversion)

importer = ezdxf.Importer(source_dwg, target_dwg)
importer.import_all()
target_dwg.saveas('test.dxf')
But I got errors:
Traceback (most recent call last):
  File "E:/reseaux/example.py", line 56, in <module>
    importer.import_all()
  File "C:\Users\y.song\AppData\Local\Programs\Python\Python36\lib\site-packages\ezdxf\tools\importer.py", line 39, in import_all
    self.import_modelspace_entities()
  File "C:\Users\y.song\AppData\Local\Programs\Python\Python36\lib\site-packages\ezdxf\tools\importer.py", line 52, in import_modelspace_entities
    target_modelspace.add_entity(new_entity)  # add entity to modelspace
  File "C:\Users\y.song\AppData\Local\Programs\Python\Python36\lib\site-packages\ezdxf\legacy\layouts.py", line 124, in add_entity
    for linked_entity in entity.linked_entities():
  File "C:\Users\y.song\AppData\Local\Programs\Python\Python36\lib\site-packages\ezdxf\dxfentity.py", line 136, in linked_entities
    entity = wrap(link)
  File "C:\Users\y.song\AppData\Local\Programs\Python\Python36\lib\site-packages\ezdxf\legacy\factory.py", line 102, in wrap_handle
    raise DXFKeyError('invalid handle #{}'.format(handle))
ezdxf.lldxf.const.DXFKeyError: 'invalid handle #28A23'

ezdxf cannot create new handle for blocks.

Do you knows where is the problem? 
Thanks,

Best regards
To unsubscribe from this group and stop receiving emails from it, send an email to python-ezdxf...@googlegroups.com.

Manfred Moitzi

unread,
Jan 18, 2019, 10:42:23 PM1/18/19
to python-ezdxf
Same answere as on GitHub:

  1. It is not possible to fix anything without the used data!
  2. WHY are you importing the data into a new drawing, just open the source drawing and save  it as a new file.
  3. For the upcoming release 0.9.0: moved Importer() from ezdxf.tools to ezdxf.addons - internal structures of modern DXF files are too complex and too undocumented to support importing data in a reliable way - using Importer() may corrupt your DXF files or just don't work!
Don't relay on this feature, it may be removed in the future.
Reply all
Reply to author
Forward
0 new messages