When importing dxfs, you get a window asking you to select vector layers to add. With all the dxfs I've imported so far, that has had two layers called entities, one of which is points and one of which is linestrings. I select all, click OK, and then the file imports. This has to be done for each dxf.

Today I had to import approximately 200 dxfs (which I eventually combined using the data management tools.) Having to click on select all and then on OK, to select the vector layers for each and every one of those dxfs was very tedious!

Is it possible to set QGIS to select all automatically as it imports dxfs, without my having to sit there for half an hour repeating those clicks?

The dxfs were created from NTF tiles, using the LL2DXF converter. Unfortunately, many of them will not open in Autocad due to an invalid block name so I can't combine them in CAD if there are lots. I do have a script that can strip out the blocks, but it is a little slow and has to be used one file at a time. That's OK for a small number, but today I had a very large area of map to convert and there are other towns to do over the coming weeks.


2 Answers 2


If you want to take the Python route, you could use the answer posted at Loading DXF file as vector layer using PyQGIS? with some slight edits. I suggest (if you haven't already done so) to copy all your .dxf files to a single directory. Copy/paste the code below into a text editor and change the path variable path = "path/to/DXF" to the path for your directory. Then in QGIS, open the Python Console from the menubar Plugins > Python Console or press Ctrl + P, copy/paste the code from the text editor. This is the code:

import glob, os

# Enter directory path which holds the .dxf files (e.g. "C:/Users/You/Desktop/DXF folder/")
path = "path/to/DXF"
for layer in glob.glob(path + "*.dxf"):
    vlayer = QgsVectorLayer(layer, 'name', 'ogr')
    subLayers = vlayer.dataProvider().subLayers()
    for subLayer in subLayers:
        geom_type = subLayer.split(':')[-1]
        uri = "%s|layername=entities|geometrytype=%s" % (layer, geom_type,)
        dxf_file_name = os.path.splitext(os.path.basename(layer))[0]
        layer_name = "%s - %s" % (dxf_file_name,geom_type,)
        sub_vlayer = QgsVectorLayer(uri, layer_name, 'ogr')

This should prevent you from sitting there for half an hour :)

Note that if this answer helps (which is essentially the same as the one I linked to) then your question should be flagged as a duplicate.


Test the PlugIn Another DXF Importer / DXF2Shape Converter

Multiple files can be imported at the same time (batch import). One click for a lot of files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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