Bug report #18270

QGIS 3.0 import dxf python code issue

Added by PJ Lightning over 2 years ago. Updated over 2 years ago.

Status:Closed
Priority:High
Assignee:-
Category:Python bindings / sipify
Affected QGIS version:3.0.0 Regression?:Yes
Operating System:Win7 Pro Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:No Copied to github as #:26161

Description

The code:
import glob, os
path = "E:/aawork/etc/etc/etc/dxfs/"
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]
if geom_type == 'Point':
uri = "%s|layername=entities|geometrytype=%s" % (layer, geom_type,)
dfx_file_name = os.path.splitext(os.path.basename(layer))[0]
layer_name = "%s - %s" % (dfx_file_name,geom_type,)
sub_vlayer = QgsVectorLayer(uri, layer_name, 'ogr')
QgsMapLayerRegistry.instance().addMapLayer(sub_vlayer)

In QGIS 2.18, this code imports points from all the dxfs in the folder.
In 3.0 it just triggers a series of boxes to select the CRS but then nothing imports.

History

#1 Updated by Giovanni Manghi over 2 years ago

  • Category changed from PyQGIS Console to DWG/DXF import
  • Status changed from Open to Feedback

Does it work as expected in 2.18?

#2 Updated by PJ Lightning over 2 years ago

Giovanni Manghi wrote:

Does it work as expected in 2.18?

Yes. Sorry, it seems that all the code indents vanished when I saved the report.
It works as expected in 2.18. It imports the points (labels on several maps), which I can then easily merge into one shape file.

#3 Updated by Giovanni Manghi over 2 years ago

  • Regression? changed from No to Yes
  • Status changed from Feedback to Open
  • Priority changed from Normal to High

#4 Updated by Nyall Dawson over 2 years ago

  • Status changed from Open to Closed

Check the return value of subLayers(). The format is different and no longer separated by ':' characters alone.

#5 Updated by PJ Lightning over 2 years ago

  • Status changed from Closed to Reopened

Nyall Dawson wrote:

Check the return value of subLayers(). The format is different and no longer separated by ':' characters alone.

Hi, could you repeat that in English, please?
The code was written for me by someone who understands coding. I have no idea what your reply means.
It worked in the last version and does not work now.

#6 Updated by Salvatore Larosa over 2 years ago

  • Category changed from DWG/DXF import to Python bindings / sipify

and you should to get an error on this line as well: QgsMapLayerRegistry.instance().addMapLayer(sub_vlayer)

#7 Updated by Giovanni Manghi over 2 years ago

  • Status changed from Reopened to Closed
  • Resolution set to invalid

PJ Lightning wrote:

Nyall Dawson wrote:

Check the return value of subLayers(). The format is different and no longer separated by ':' characters alone.

Hi, could you repeat that in English, please?

the code needs to be changed to work in qgis 3.

#8 Updated by PJ Lightning over 2 years ago

Giovanni Manghi wrote:

PJ Lightning wrote:

Nyall Dawson wrote:

Check the return value of subLayers(). The format is different and no longer separated by ':' characters alone.

Hi, could you repeat that in English, please?

the code needs to be changed to work in qgis 3.

If this isn't a bug, where is the information that would explain how to alter the code?
3.0 is completely useless if the codes don't work. The download didn't include telepathic powers.

#9 Updated by Giovanni Manghi over 2 years ago

If this isn't a bug, where is the information that would explain how to alter the code?
3.0 is completely useless if the codes don't work. The download didn't include telepathic powers.

??? in any software at any new major release changes are expected.

Also available in: Atom PDF