Select to view content in your preferred language

ListDatasets with "CAD" keyword not working?

841
3
01-21-2011 12:28 AM
StefanHaglund1
Esri Contributor
All,

arcpy.ListDatasets and I can�??t seem to agree.  I want to list all CAD datasets in a folder and according to the help I should be able to use arcpy.ListDatasets with the �??CAD�?� keyword.

If I write this, I get all my CAD data but also everything else:
import arcpy
from arcpy import env
env.workspace = "C:\\data"
datalist = arcpy.ListDatasets("*", "All")
for data in datalist:
    print data


If I write the following code, nothing gets listed:
import arcpy
from arcpy import env
env.workspace = "C:\\data"
cadlist = arcpy.ListDatasets("*", "CAD")
for cad in cadlist:
    print cad


In the �??Listing data�?� section it lists CAD as one of the keywords. (http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z00000011000000.htm)
But in the ListDatasets topic there is no mention of the CAD keyword.
( http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000001m000000.htm )

For now, I get by with this, which isn't optimal.
cadlist = arcpy.ListDatasets("*.dwg", "All")


Has anyone successfully used the CAD keyword and could you then help me out with what works?

ESRI, I think the help section needs to be corrected.

Thanks!
0 Kudos
3 Replies
AnantThunuguntla
Occasional Contributor
All,

arcpy.ListDatasets and I can�??t seem to agree.  I want to list all CAD datasets in a folder and according to the help I should be able to use arcpy.ListDatasets with the �??CAD�?� keyword.

If I write this, I get all my CAD data but also everything else:
import arcpy
from arcpy import env
env.workspace = "C:\\data"
datalist = arcpy.ListDatasets("*", "All")
for data in datalist:
    print data


If I write the following code, nothing gets listed:
import arcpy
from arcpy import env
env.workspace = "C:\\data"
cadlist = arcpy.ListDatasets("*", "CAD")
for cad in cadlist:
    print cad


In the �??Listing data�?� section it lists CAD as one of the keywords. (http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z00000011000000.htm)
But in the ListDatasets topic there is no mention of the CAD keyword.
( http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000001m000000.htm )

For now, I get by with this, which isn't optimal.
cadlist = arcpy.ListDatasets("*.dwg", "All")


Has anyone successfully used the CAD keyword and could you then help me out with what works?

ESRI, I think the help section needs to be corrected.

Thanks!


Try this:

import arcgisscripting
gp = arcgisscripting.create(9.3)
gp.workspace = "C:\\data"
gp.listdatasets("", "CAD")

output:
[u'a.dgn', u'a.DWG']
0 Kudos
StefanHaglund1
Esri Contributor
Thanks anant!

That works! What is the plan for 10, will this be fixed in the future?

Nooski
0 Kudos
BatesRambow
Regular Contributor
I recently ran into this same problem, and agree that the CAD feature type is missing from the ListDatasets function in arcpy.  However, I found a workaround that I think will work better than using the older arcgisscripting toolset. 

The following code is an example: Set the workspace using sys.argv, create an empty list, use the arcpy.Describe method and then loop through the dataTypes in the directory.  You can use a conditional statement to append only the CAD datasets to the list:

import sys, arcpy

arcpy.env.workspace = sys.argv[1]  #User will enter a file path for a directory of CAD files
files = arcpy.ListDatasets() #List all datasets. 
CADfiles = [] #Create an empty list to store CAD files
for f in files:[INDENT]desc = arcpy.Describe(f)
if desc.dataType == "CadDrawingDataset":[INDENT]CADfiles.append(f)[/INDENT][/INDENT]


You can also use arcpy.ListDatasets("", "Feature") - this will return all coverage, CAD, and geodatabase feature datasets.  You'd still need to do the conditional statement, so this wouldn't really be necessary.
0 Kudos