Single Line Fonts Export - Terrible output

Solution :

import ezdxf
def change_text_fonts(input_filename, output_filename):
    """Change the font of all text entities in a DXF file to a single-line SHX font."""
    # Open the DXF file
    try:
        doc = ezdxf.readfile(input_filename)
    except IOError:
        print(f"Cannot open file: {input_filename}")
        return
    except ezdxf.DXFStructureError:
        print(f"Invalid or corrupted DXF file: {input_filename}")
        return
    # Access the text styles in the document
    styles = doc.styles
    # Specify the desired SHX font and style name
    font_name = 'romans.shx'  # You can choose 'simplex.shx', 'txt.shx', etc.
    style_name = 'SingleLineFont'
    # Create a new text style with the SHX font if it doesn't exist
    if style_name not in styles:
        styles.new(style_name, dxfattribs={'font': font_name})
        print(f"Created new text style '{style_name}' with font '{font_name}'.")
    else:
        # Ensure the existing style uses the correct font
        style = styles.get(style_name)
        style.dxf.font = font_name
        print(f"Updated text style '{style_name}' to use font '{font_name}'.")
    # Find all TEXT and MTEXT entities in the entire drawing
    text_entities = doc.query('TEXT MTEXT')
    # Change the text style of each entity to the new style
    for text_entity in text_entities:
        old_style = text_entity.dxf.style
        text_entity.dxf.style = style_name
        print(f"Changed text entity from style '{old_style}' to '{style_name}'.")
    # Save the modified DXF to the output file
    try:
        doc.saveas(output_filename)
        print(f"Saved modified DXF file as '{output_filename}'.")
    except IOError:
        print(f"Cannot save file: {output_filename}")
        return
if name == 'main':
    # Replace 'input.dxf' and 'output.dxf' with your file paths
    input_dxf = 'Z:\\#_B -ShipDesigner Light (farouk-marida)\\Utils\\cirone1.dxf'
    output_dxf = 'Z:\\#_B -ShipDesigner Light (farouk-marida)\\Utils\\cirone1convert.dxf'
    change_text_fonts(input_dxf, output_dxf)

Open this with autocad true view It will view the text poorly (or microstation)
textdwg.dwg (118.9 KB)
In Rhinoceros the font is correctly one line when exploded, but when exported to dwg the font becomes unreadable.

IS there any single line font that is cross compatible with Autocad so that when exploded it becomes single lines?

Thats needed for CNC

What’s one possible solution?

Steps my client does :
-Generates the nesting files
-Exports them in DWG

The exported DWG file should have Texts that when exploded become OneLines, so we need a font that we can export from RHino that DWG correctly interprets as font that when exploded becomes one line.

Hi, @farouk.serragedine. Is there a reason exploding the single-line text in Rhino before exporting to DWG is not acceptable? In your example file, you could just select all text on DOCUMENTAZIONE$NEST$texts and Explode, then File > Save a Copy > AutoCAD DWG. Maybe you still need to edit the text in AutoCAD?

Your file looks pretty darn good in AutoCAD 2025, fwiw.

– Dale

1 Like


This is what I see when I open it with DWG true view 2025

Yes since sometimes production is split among multiple subcontractors sometimes they change the texts before exploding them therefore we need a single line font that we can export from rhino onto dwg

That is what a single line font looks like when the program thinks it’s a normal font.

Solution for anyone having this problem :

import ezdxf
def change_text_fonts(input_filename, output_filename):
    """Change the font of all text entities in a DXF file to a single-line SHX font."""
    # Open the DXF file
    try:
        doc = ezdxf.readfile(input_filename)
    except IOError:
        print(f"Cannot open file: {input_filename}")
        return
    except ezdxf.DXFStructureError:
        print(f"Invalid or corrupted DXF file: {input_filename}")
        return
    # Access the text styles in the document
    styles = doc.styles
    # Specify the desired SHX font and style name
    font_name = 'romans.shx'  # You can choose 'simplex.shx', 'txt.shx', etc.
    style_name = 'SingleLineFont'
    # Create a new text style with the SHX font if it doesn't exist
    if style_name not in styles:
        styles.new(style_name, dxfattribs={'font': font_name})
        print(f"Created new text style '{style_name}' with font '{font_name}'.")
    else:
        # Ensure the existing style uses the correct font
        style = styles.get(style_name)
        style.dxf.font = font_name
        print(f"Updated text style '{style_name}' to use font '{font_name}'.")
    # Find all TEXT and MTEXT entities in the entire drawing
    text_entities = doc.query('TEXT MTEXT')
    # Change the text style of each entity to the new style
    for text_entity in text_entities:
        old_style = text_entity.dxf.style
        text_entity.dxf.style = style_name
        print(f"Changed text entity from style '{old_style}' to '{style_name}'.")
    # Save the modified DXF to the output file
    try:
        doc.saveas(output_filename)
        print(f"Saved modified DXF file as '{output_filename}'.")
    except IOError:
        print(f"Cannot save file: {output_filename}")
        return
if name == 'main':
    input_dxf = 'Z:\\#_B -ShipDesigner Light (farouk-marida)\\Utils\\cirone1.dxf'
    output_dxf = 'Z:\\#_B -ShipDesigner Light (farouk-marida)\\Utils\\cirone1convert.dxf'
    change_text_fonts(input_dxf, output_dxf)
  1. Convert to DXF
  2. Convert the style to one line (compatible with Autocad)
  3. You now have a DXF with the corret text style
  4. COnvert it to Dwg
    The macro above is a sample script to show how to update styles.

Would still be great to have a native solution this oneline dwg conversion process is normal in manufacturing and I want to keep my customers on Rhino as a sole platform.
Basically what we miss is a font that when exported to DWG if oneline becomes “ENGENEERING” or “SIMPLEX” or something supported by Autocad,Microstation and 2d softwares as effectively one line.
@dale @stevefuchs

Thank you for your fast responses.

Hi @farouk.serragedine - I’ve logged the issue/wish.

https://mcneel.myjetbrains.com/youtrack/issue/RH-84796

– Dale

1 Like