# Option A : When you're executing code in-process #
import arcpy
# Use this line if you're not sure if it's already true
arcpy.env.addOutputsToMap = True
# Executing tool will automatically add layer to map
arcpy.management.MakeFeatureLayer(r"Path\To\GDB\FeatureClass", "NameForLayer")
# Option B : When you're executing code out-of-process #
import arcpy
# Hook into the map document
mxd = arcpy.mapping.MapDocument(r"Path\To\MapDocument")
# Hook into the data frame where you want to add the layer
df = arcpy.mapping.ListDataFrames(mxd)[0]
# Create a Layer object
lyr = arcpy.management.MakeFeatureLayer(r"Path\To\GDB\FeatureClass", "NameForLayer").getOutput(0)
# Add the layer object to the map
arcpy.mapping.AddLayer(df, lyr)
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。