Create map for each feature class in workspace

433
2
Jump to solution
03-06-2020 02:12 AM
GeorgiyYaroslavtsev
New Contributor

Hi!

Can somebody tell me is it possible to automate creating maps for each feature class in workspace in ArcMap with ModelBuilder or ArcPy?

0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

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))

View solution in original post

2 Replies
JakeSkinner
Esri Esteemed Contributor

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))
GeorgiyYaroslavtsev
New Contributor

Many thanks! You saved me a lot of time today! 😃

0 Kudos