# Import system modules
import arcpy
import os
from arcpy import env
from arcpy import interop
# Set local variables
input_cad_folder = "C:\Users\LL\Desktop\CAD"
output_gdb_folder = "C:\data"
output_folder="C:\output"
for found_file in os.listdir(input_cad_folder):
# Searches for .dwg files
if found_file.endswith(".dwg"):
print "Converting: "+found_file
input_cad_dataset = os.path.join(input_cad_folder, found_file)
print "Converting: "+input_cad_dataset
output_gdb = found_file.split(".")[0] +".gdb"
output_gdb_path = os.path.join(output_gdb_folder, output_gdb)
print "Converting: "+output_gdb_path
try:
interop.QuickImport(input_cad_dataset, output_gdb_path)
env.workspace = output_gdb_path
fcs = arcpy.ListFeatureClasses("*")
output_shp_path=output_folder+output_gdb.split(".")[0]
print "Create: "+output_shp_path
os.makedirs(output_shp_path)
for fc in fcs:
outfc = arcpy.ValidateTableName(fc)
print "Create: "+outfc
arcpy.FeatureClassToShapefile_conversion([outfc], output_shp_path)
except:
print arcpy.GetMessage()