The DXF is real 3D (Z-value not attribute)?
Then test the following:
-dim val:(starting with GDAL 1.10) Force the coordinate dimension to val (valid values are XY, XYZ, XYM, and XYZM - for backwards
compatibility 2 is an alias for XY and 3 is an alias for XYZ). This
affects both the layer geometry type, and feature geometries. Starting
with GDAL 1.11, the value can be set to "layer_dim" to instruct
feature geometries to be promoted to the coordinate dimension declared
by the layer. Support for M was added in GDAL 2.1
processing.runalg('gdalogr:convertformat',dxfdat , 0,sql1 + opt1 + ' -dim XYZ', shpLinestring)
A polyline usually has different z-values. As an attribute, you can only put one Z value for the entire line.
If that's enough for you, create a new field in the field calculator:
Another way with SQLite-Synax:
Write the z-Value from the first point of LineString to Attribut
opt1="-skipfailure --config DXF_MERGE_BLOCK_GEOMETRIES FALSE --config DXF_INLINE_BLOCKS TRUE -dim XYZ -nlt LINESTRING "
sql1= "-dialect sqlite -sql \"SELECT *,ST_Z(ST_StartPoint (geometry)) as elevation, ogr_style from entities where GeometryType(geometry) LIKE '%LINESTRING%'\" "
processing.runalg('gdalogr:convertformat',dxfdat , 0,opt1 + sql1, shpLinestring)