1

I have 19 unprojected CAD files in a Folder. Some are .dwg and .dxf extension. I am attempting to convert these CAD files to a GDB using the arcpy.CADToGeodatabase_conversion() tool

enter image description here

I wrote this little script below and it gives me an error

import arcpy
import os
CADpath = 'path\\CADstuff'
GDB = 'path\\CAD.gdb'
sr = '3424'
for cad in os.listdir(CADpath):
    cadname = str(cad[:-4])
    arcpy.CADToGeodatabase_conversion(cad, GDB, cadname,'',sr)
    print cadname




  Traceback (most recent call last):
  File "path\CADtoGDB.py", line 9, in <module>
    arcpy.CADToGeodatabase_conversion(cad, GDB, cadname,reference_scale,sr)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\conversion.py", line 1637, in CADToGeodatabase
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input CAD Datasets: Dataset 080401_DLU_2012-06-21.dwg does not exist or is not supported
Failed to execute (CADToGeodatabase).

*GDB created before script *First time working with CAD files

2
  • 2
    trying adding this into your script arcpy.env.workspace = CADpath before you start the loop.
    – KHibma
    Sep 12, 2016 at 15:51
  • wow that worked! put it as an answer il accept it. Can you elaborate on why that worked? i have written standalone python scripts without defining the work space and they have worked before
    – ziggy
    Sep 12, 2016 at 16:01

1 Answer 1

0

As is - your script is just pushing in filename.dwg into the CAD tool. The CAD tool has no idea where to find this file. Its like me saying "I live on 5th Street". By adding in arcpy.env.workspace = CADpath, you're telling the tool where to look. Like saying "I live in New York City", thus you know what city to look for 5th Street.

import arcpy
import os
CADpath = 'path\\CADstuff'
GDB = 'path\\CAD.gdb'
sr = '3424'
arcpy.env.workspace = CADpath
for cad in os.listdir(CADpath):
    cadname = str(cad[:-4])
    print cadname
    arcpy.CADToGeodatabase_conversion(cad, GDB, cadname,'',sr)

I'd also move the print cadname up. That way it'll show he name its working on before trying to run the tool. It may have given you a clue that the path wasn't fully qualified and the tool couldnt find the dataset.

Or you could fully qualify the file path....

import arcpy
import os
CADpath = 'path\\CADstuff'
GDB = 'path\\CAD.gdb'
sr = '3424'
for cad in os.listdir(CADpath):
    cadname = str(cad[:-4])
    print cadname
    arcpy.CADToGeodatabase_conversion(os.path.join(CADpath, cad), GDB, cadname,'',sr)
0

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.