Select to view content in your preferred language

Create map for each feature class in workspace

557
2
Jump to solution
03-06-2020 02:12 AM
GeorgiyYaroslavtsev
Emerging 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
Emerging Contributor

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

0 Kudos