I am essentially running this script but for my own data. The problem I am having is that the ListDatasets command is not recognizing the CAD .dwg files as datasets (as it should). It returns a 'None' after the arcpy.ListDatasets.

Can anyone tell me why this is?

(modules loaded earlier in script, print statements added for debugging purposes)

    arcpy.env.workspace = ("C:\\SY\\projects\\CGI\\test\\script_test\\CAD\\"+ FC)
    print arcpy.env.workspace
    arcpy.env.overwriteOutput = True
    vTab = arcpy.ValueTable()
    print arcpy.ListDatasets("W*.dwg")
    for fd in arcpy.ListDatasets("W*.dwg"):
        print 'Adding: ', fd
        layername = fd + "_Layer"
        arcpy.MakeFeatureLayer_management(fd + "/Polyline", layername, "\"Layer\" = 'C-DD-ALIGN' ")
    arcpy.Merge_management(vTab, r"C:\SY\projects\CGI\test\script_test\sratch.gdb\test")

And here are the results I get

    >>> None
    >>> ArcPy ERRORS:

  • What is FC in your first line? Is that a valid folder name e.g. C:\SY\projects\CGI\test\script_test\CAD\FolderName? – Midavalo Mar 15 '17 at 4:10
  • Your code above works for me, so I'm guessing it's not finding any DWG files in that folder or it wasn't supported at 10.1. – Midavalo Mar 15 '17 at 4:11
  • The FC is part of a larger loop. It's purpose is to iterate through all of the DWG's in a folder. However, it doesn't seem to be working properly. When I delete the FC the script runs just fine. Refer to @Midavalo 's post below. – Simon.y Mar 15 '17 at 15:50
  • Does the FC refer to a folder or a file? A dataset is a container of feature classes (etc.), so to list datasets you'd need to look at a folder or geodatabase to find those datasets. To find a CAD dataset your path needs to be a folder, not a file. – Midavalo Mar 15 '17 at 15:53

Your code works fine for me - it looks like arcpy.ListDatasets() does in fact support CAD files, although not when using the "CAD" keyword (which you have excluded anyway).

import arcpy
arcpy.env.workspace = (r"D:\GIS\SE\Cad")

# Without "CAD" keyword
print "No keyword"
print arcpy.ListDatasets("m*.dwg")

# With "CAD" keyword
print "CAD keyword"
print arcpy.ListDatasets("m*.dwg", "CAD")

Which outputs:

No keyword
[u'Midavalo.DWG', u'midavalo1.DWG']
CAD keyword

I suspect the issue may be in your arcpy.env.workspace path. Check that the path created by

"C:\SY\projects\CGI\test\script_test\CAD\"+ FC

is actually a valid path containing DWG files. Also check they are DWG and not DXF files (otherwise you'd need to use arcpy.ListDatasets("W*.DXF") instead)

| improve this answer | |
  • Yup, the '+ FC' is a variable in the loop and doesn't seem to be working properly. When I delete that piece it runs no problem. – Simon.y Mar 15 '17 at 15:45
  • 2
    IMO os.path.join() is a better choice for building file path strings. – Bjorn Mar 15 '17 at 16:17

The documentation for walk in the Data Access module lists CadDrawing as a valid data type to filter the results. You should be able to incorporate it into your script to replace for fd in arcpy.ListDatasets("W*.dwg"):

| improve this answer | |

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.