Search code examples
dxf

Using dxfwrite or ezdxf to create dxf text in z direction


I would like to use either dxfwrite or ezdxf to create text along (WCS) y direction, and with height in the (WCS) z direction.

Using autocad, I have done this by setting UCS and entering text.

How can I do in dxfwrite or ezdxf (or any other python friendly library)?

dxf.ucs('textucs',xaxis=(0.,1.,0),yaxis=(0.,0.,1.))
lab = dxf.mtext('hello',np.array([0.,0.,.5]),layer='mylay',height=0.3)

doesn't work, presumably because I have only created UCS, and am not using it.


Solution

  • Defining an UCS does nothing, dxfwrite/ezdxf are not CAD applications.

    This example uses ezdxf to write a text in the YZ-plane:

    import ezdxf
    
    dwg = ezdxf.new('ac1015')
    modelspace = dwg.modelspace()
    modelspace.add_mtext("This is a text in the YZ-plane",
                         dxfattribs={
                             'width': 12,  # reference rectangle width
                             'text_direction': (0, 1, 0),  # write in y direction
                             'extrusion': (1, 0, 0)  # normal vector of the text plane
                         })
    
    dwg.saveas('mtext_in_yz_plane.dxf')
    

    mtext in dxfwrite is just a bunch of TEXT entities, because the MTEXT entity requires DXF13 or later.