# Python script to implement a batch import of CAD files into Geodatabase

Please does anyone know where I can get a python script that can do a batch import of CAD files into a Geodatabase.

I have one I wrote here, but it is only able to import one CAD file at a time. It imports the CAD files and splits it into feature classes and stores it in the geodatabase via the feature dataset. It works perfectly well but I need to loop the script to search through a given folder for all the cardfiles in it and import them under different feature datasets and put all the datasets into one geodatabase.

# Name: CadtoGeodatabase.py
# Description: Create a feature dataset
# Author: Irene
# Import system modules
import arcpy
from arcpy import env

# Set workspace
env.workspace = "C:/data1"

# Set local variables
reference_scale = "1500"

# Create a FileGDB for the fds

# Execute CreateFeaturedataset

-

You'll just need to use a for loop and if statement to find all the files you need. I haven't tested the code below with CAD files but it should be what you're after (or at least provide the structure to do so).

# Import system modules
import arcpy, os
from arcpy import env

# Set local variables

output_gdb_folder = "C:\data"
output_gdb_path = os.path.join(output_gdb_folder, output_gdb)

reference_scale = "1500"

# Create a FileGDB for the fds
try:
arcpy.CreateFileGDB_management(output_gdb_folder, output_gdb)
except:
pass

# For loop iterates through every file in input folder
# Searches for .dwg files
if found_file.endswith(".dwg"):

print "Converting: "+found_file
try:
except:
print arcpy.GetMessage()

-

You can use the code below to search a given folder and subfolders for .dwg files and then use this list as an input to your script.

# Creates a list of all the files with the given list of extensions and search strings
# CAUTION:  This is dangerous!  For example, if top == '/', it
# could affect all your disk files.

#Licence: Creative Commons
#Created by: George Corea; georgec@atgis.com.au, coreagc@gmail.com

import os, sys, datetime, arcpy

top = os.getcwd() # change to a specific path if required.
# This otherwise starts with the directory the script is in.
RootOutput = top # change if you want output somewhere else
FileTypes=['dwg'] # add filetypes or as required. '' for all files (remember .shp has 4 or 5 other associated files)
SearchStrings=[''] # add strings as required use format ['search1','search2'] etc.

filecount=0
#successcount=0
#errorcount=0

print "Working in: "+os.getcwd()

List =[]

for root, dirs, files in os.walk(top, topdown=False):
for fl in files:
currentFile=os.path.join(root, fl)
for FileType in FileTypes:
status= str.endswith(currentFile,FileType)
if str(status) == 'True':
for SearchString in SearchStrings:
if str(SearchString in currentFile) == 'True':
#print str(currentFile)+str(status)
List.append(currentFile)
filecount=filecount+1

print 'File List: ' + str(List) + " with "+ str(len(List)) + " objects."
# Replace following with whatever arcpy. tool you want to run using the list as an input.


then you can do the following

for item in List