Hi!
Can somebody tell me is it possible to automate creating maps for each feature class in workspace in ArcMap with ModelBuilder or ArcPy?
Solved! Go to Solution.
You can run the following code in ArcMap. Just replace arcpy.env.workspace with the path to you geodatabase.
import arcpy, os
arcpy.env.workspace = r"C:\temp\python\test.gdb"
for fc in arcpy.ListFeatureClasses("*"):
fcName = str(fc)
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
arcpy.MakeFeatureLayer_management(os.path.join(arcpy.env.workspace, fc), fcName)
mxd.saveACopy(r"C:\temp\python\{0}.mxd".format(fcName))
You can run the following code in ArcMap. Just replace arcpy.env.workspace with the path to you geodatabase.
import arcpy, os
arcpy.env.workspace = r"C:\temp\python\test.gdb"
for fc in arcpy.ListFeatureClasses("*"):
fcName = str(fc)
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
arcpy.MakeFeatureLayer_management(os.path.join(arcpy.env.workspace, fc), fcName)
mxd.saveACopy(r"C:\temp\python\{0}.mxd".format(fcName))
Many thanks! You saved me a lot of time today! 😃