I'm trying to convert shapefiles into one DXF file using pyqgis, I started with one layer, the problem is that I can't open the DXF file after conversion.

I've tried two approaches but still getting the same problem.
First approach: based on this answer
from PyQt4.QtCore import QFile
dxfExport = QgsDxfExport()
layers=[QgsDxfExport.DxfLayer(iface.activeLayer())]
settings = iface.mapCanvas().mapSettings()
dxfExport.setMapSettings( settings )
dxfExport.addLayers( layers )
dxfExport.setLayerTitleAsName(True)
dxfExport.setDestinationCrs(26191)
dxfExport.setForce2d( True )
dxfFile = QFile( 'C:\\Users\\Desktop\\test\\file.dxf' )
dxfExport.writeToFile( dxfFile, 'utf-8')
second approach : based on this answer
I converted my shapefile to geojson then used FWtools to convert the geojson file to dxf.
ogr2ogr -f DXF test.dxf test.geojson
Is it possible to access source code of 'project>DXF export' funcionality ?
import subprocess command = ["C:\Program Files\QGIS 2.18\bin\ogr2ogr.exe","-f", "DXF","C:\Users\Desktop\output_dxf.dxf","C:\Users\Desktop\b\input_shp.shp"] subprocess.check_call(command) . But I steel can't convert many shapfiles to one DXF file
– ayar anasse Oct 25 '18 at 13:43