3

I'm trying to run 'Export Project to DXF' in QGIS using the Python console. The intention is to export multiple vector layers, as defined by a Theme Visibility State, in the same way as if you utilized the standard dialog box.

I've written some code based on other posts and the qgisapp.cpp, but I'm stuck trying to input multiple layers in the theme to QgsDxfExport.DxfLayer.

The code below will halt because the output of lyr_names is a list, does DxfLayer even support multiple inputs?

Any ideas?

dxfExport = QgsDxfExport()
lyr_names = [layer for layer in QgsProject.instance().mapThemeCollection().mapThemeVisibleLayers('Theme_Name')]
dxfExport.setMapSettings( settings )
dxfExport.addLayers( [QgsDxfExport.DxfLayer(lyr_names)] )
dxfExport.setSymbologyScale(200)
dxfExport.setSymbologyExport(1)
dxfExport.setLayerTitleAsName(-1)
dxfExport.setDestinationCrs(QgsCoordinateReferenceSystem("EPSG:28356"))
dxfExport.setForce2d(0)
dxfExport.setExtent(new_box)

dxfFile = QFile('C:/Temp/plots/test2.dxf')
dxfExport.writeToFile( dxfFile, 'CP1252' )

1 Answer 1

5

Does DxfLayer even support multiple inputs?

No. The error QgsDxfExport.DxfLayer(QgsDxfExport.DxfLayer): argument 1 has unexpected type 'list' states that, explicitly.

But you can use

dxfExport.addLayers([QgsDxfExport.DxfLayer(lyr) for lyr in lyr_names])
1
  • Great, thanks, i understand now
    – kelvin
    Jan 21 at 22:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.