0

I would like to copy over these complex linetypes to a new DXF file.

I can grab most of the information using

doc = ezdxf.addons.odafc.readfile(filepath) for linetype in doc.linetypes: print(linetype.dxfattribs()

This returns the dict including name and description, like this :

{'handle': '2A41E', 'owner': '5', 'name': "X832-003-UTEX$0$3''GAS", 'flags': 0, 'description': "----3''G----3''G----"}

But this is missing the pattern.

I do not have an acad.lin file, but the DWG still shows the correct linetype, so it must be available somewhere within the .dwg.

I tried dxf2code, but I've only been able to output code that will create a line that applies the style. I've also tried using the Importer library, but the complex linetypes are turned to simple linetypes, and the text symbols integrated in the line are turned to points.

postgrease
  • 11
  • 3

1 Answers1

0

The included ezdxf.addons.Importer add-on can do that. The following code imports the linetype "LType2" into a new DXF document:

import ezdxf
from ezdxf.addons import Importer

source_doc = ezdxf.readfile("source.dxf")
target_doc = ezdxf.new()

importer = Importer(source_doc, target_doc)
importer.import_table("linetypes", entries="LType2")
# entries=("LType1", "LType2", ...) imports multiple line types
# entries="*" imports all line types, this is the default case
importer.finalize()

target_doc.saveas("target.dxf")

For more information about the Importer add-on read the docs.

mozman
  • 2,001
  • 8
  • 23
  • really appreciate you taking the time to answer and for building such a useful tool! I've moved the discussion to your [github](https://github.com/mozman/ezdxf/discussions/809) because I think bug-reporting may be more appropriate over there. I'll update this question once that's been cleared out. – postgrease Dec 23 '22 at 16:38
  • template = doc.layers.get(layer_name) layer_attribs = template.dxf.all_existing_dxf_attribs() Removing from the list items like `'insert'`, `'location'` give a template to work on – postgrease Apr 04 '23 at 05:21