Skip to content

Add option to use layer names in DXF export (#2439) - #2447

Open
goanscryca wants to merge 1 commit into
KLayout:masterfrom
goanscryca:fix/issue-2439
Open

goanscryca wants to merge 1 commit into
KLayout:masterfrom
goanscryca:fix/issue-2439

Conversation

@goanscryca

Copy link
Copy Markdown

This PR addresses #2439 by adding support for exporting DXF layers with their original layout layer names instead of prefixing layer/datatype numbers (e.g. PAD instead of L18D0_PAD).

Changes

  1. DXFWriterOptions (dbDXFFormat.h):
    • Added use_layer_names boolean flag (defaults to false for backwards compatibility).
  2. DXFWriter::write (dbDXFWriter.cc):
    • Uses db::SaveLayoutOptions::LP_AssignNameWithPriority when use_layer_names is true, preserving layer names directly as DXF layer names.
  3. GSI & Python/Ruby bindings (gsiDeclDbDXF.cc, dbcore.pyi, laySaveLayoutOptions.rb):
    • Added dxf_use_layer_names / dxf_use_layer_names= accessors on SaveLayoutOptions.
  4. GUI Option Page (DXFWriterOptionPage.ui, layDXFWriterPlugin.cc):
    • Added "Use layer names (don't prefix with layer/datatype numbers)" checkbox to the DXF export options dialog.
  5. XML persistence (dbDXF.cc):
    • Added XML serialization for use-layer-names.
  6. CLI buddy options (bdWriterOptions.h, bdWriterOptions.cc, bdBasicTests.cc):
    • Added --use-layer-names flag to generic writer options.
  7. Unit tests (dbDXFWriterTests.cc, bdBasicTests.cc, laySaveLayoutOptions.rb):
    • Added TEST(LayerNames) verifying DXF export with and without use_layer_names.

Fixes #2439.

Add dxf_use_layer_names option to DXFWriterOptions, SaveLayoutOptions,
buddy writer options (--use-layer-names), and GUI export dialog.
When enabled, layer names are preserved directly (e.g. 'PAD') without
prepending 'L{layer}D{datatype}' numbers.
@Kazzz-S

Kazzz-S commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

@goanscryca,

Thank you for implementing PR #2447!
I built and tested the PR on macOS, and my testing shows it provides a direct solution to the original request in #2439.

First, I confirmed the new DXF writer option:
issue-2439-DXFWriter-option

A. Layers without names

When the original KLayout layers do not have layer names:
issue-2439-A-in

the exported DXF keeps the conventional L<layer>D<datatype> names:
For example:

  • 1001/0 → L1001D0
  • 2001/1 → L2001D1
  • 3001/1 → L3001D1
issue-2439-A-out

B. Layers with names

When the KLayout layers have names:
issue-2439-B-in

with "Use layer names (don't prefix with layer/datatype numbers)" enabled, those names are directly used as the DXF layer names:
For example:

  • AAA 1001/0 → AAA
  • BBB 2001/1 → BBB
  • CCC 3001/1 → CCC
issue-2439-B-out

This is exactly the behavior @laurentc2 was looking for in the original issue: existing KLayout layer names are now preserved directly in the DXF export, while unnamed layers retain their conventional layer/datatype-based names.

Thank you very much for implementing this feature!

Best regards,
Kazzz-S

@klayoutmatthias

Copy link
Copy Markdown
Collaborator

Hi @goanscryca,

thanks for the PR. I think it's solving the issue of Laurent. I had a different solution in mind - if you do GDS to DXF translation, you will always need a layer mapping and my proposal was to have a flag that strips layer/datatype upon mapping. So a change in input translation rather than output translation. I think that this change has more use cases, i.e. for other name-based formats such as CIF.

In general, I appreciate if people talk to me before implementing something.

Anyway, I think your patch is valid and useful, conforming with the code style and it comes with tests, which is good.

I have some remarks though:

  • the *.pyi files are auto-generated, so your changes to dbcore.pyi will be overwritten
  • you do not need to use "dxf_use_layer_names?|#dxf_use_layer_names" for the method declaration of the property getter. "dxf_use_layer_names?" is enough.
  • you made an implicit release decision by saying the new properties are added in 0.30.13 - basically there should be a milestone plan first and then the implementation.
  • while fixing a small bug of mine in dbDXF.cc (the XML entity for the DXF writer options is called "cif") you created a backward compatibility problem - people having configuration files that set "polygon_mode" on DXF will now have their setting ignored. In such a case I personally tend to put in a comment in the code like "'cif' is wrong, but it's kept for backward compatibility" and keep the wrong code, but we can also change it as see what's happening. I can always blame it on this PR :)

Matthias

@klayoutmatthias klayoutmatthias added this to the 0.30.13 milestone Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

layers name in DXF file export

3 participants