Hello,
I am looking for a way in either model builder or Python (or anything at this point) to import from a table, files in a file geodatabase. I am looking at roughly 600 files in said geodatabase and it can be a little time consuming to manually pull them in to ArcGIS. The table consists of the file name and file path. Does anyone know if this is possible and if so how do I go about it.
Thanks in advance... Hopefully
Solved! Go to Solution.
Hi Patrick,
Below is some example code you can run in the Python window within ArcMap. It will iterate through a table called 'DataLocation' in the File Geodatabase 'Test'. It concatenates the fields 'FilePath' and 'FileName' to add the table/feature class it references.
import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
table = "DataLocation"
fields = ["FilePath", "FileName"]
with arcpy.da.SearchCursor(table, fields) as cursor:
for row in cursor:
path = row[0] + "\\" + row[1]
try:
fGDB_Table = arcpy.mapping.TableView(path)
arcpy.mapping.AddTableView(df, fGDB_Table)
except ValueError:
addLayer = arcpy.mapping.Layer(path)
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
del mxd, cursor
Hi Patrick,
Below is some example code you can run in the Python window within ArcMap. It will iterate through a table called 'DataLocation' in the File Geodatabase 'Test'. It concatenates the fields 'FilePath' and 'FileName' to add the table/feature class it references.
import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
table = "DataLocation"
fields = ["FilePath", "FileName"]
with arcpy.da.SearchCursor(table, fields) as cursor:
for row in cursor:
path = row[0] + "\\" + row[1]
try:
fGDB_Table = arcpy.mapping.TableView(path)
arcpy.mapping.AddTableView(df, fGDB_Table)
except ValueError:
addLayer = arcpy.mapping.Layer(path)
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
del mxd, cursor
Awesome... Thank you.
Do you think this will work using a database not in the fgdb?