I have python script that creates a point feature class. How do I send that feature to an existing map using Python?
Solved! Go to Solution.
I believe you're looking for arcpy.mapping.AddLayer().
do you mean makefeaturelayer ?
My script already makes the feature and puts it into a file geodatabase. I would like it to also take that same feature class and drop it into an ArcMap.
so I assume you have ArcMap set to add results to display and set visibility on? And I have to ask the obvious...you are running this from within ArcMap? some people have tried to add layers to arcmap without it being open
I am using Python script that runs in the background.
# Import arcpy module
import arcpy
#Import Time and Date
import time
import datetime
#Sets a variable to hold today's date in year month day (yyyymmdd)format to tag feature output name with the current date
currentdate = datetime.date.today().strftime("%Y""%m""%d")
# Overwrite pre-existing files
arcpy.env.overwriteOutput = True
# Local variables:
Changes = "\\\\MyData\\Working_Data.mdb\\Changes"
Changes_Layer = "Changes_Layer"
Updates = "\\\\MyData\\My_Data.gdb\\Updates\\Updates"+str(currentdate)
# Process: Make XY Event Layer
arcpy.MakeXYEventLayer_management(Changes, "longitude", "latitude", Changes_Layer, "", "")
# Process: Feature To Point
arcpy.FeatureToPoint_management(Changes_Layer, Updates, "CENTROID")
Now I would like to add Python script that will take "Updates"+str(currentdate)" and add it to MyDataUpdates.mxd
I believe you're looking for arcpy.mapping.AddLayer().
grief...
addLayer is what am trying to use now but I keep getting this error:
Traceback (most recent call last):
File "\\c:\MyLocation\Tools\Scripts\Changes.py", line 39, in <module>
df = arcpy.mapping.ListDataFrames(mxd, "Update")[0]
IndexError: list index out of range
This one has me stumped.
Here is the code:
# Import arcpy module
import arcpy
#Import Time and Date
import time
import datetime
#Sets a variable to hold today's date in year month day (yyyymmdd)format to tag feature output name with the current date
currentdate = datetime.date.today().strftime("%Y""%m""%d")
# Overwrite pre-existing files
arcpy.env.overwriteOutput = True
# Local variables:
Changes = "\\\\c:\\MyLocation\\\\Working_Data.mdb\\Changes"
Changes_Layer = "Changes_Layer"
Update = "\\\\c:\\MyLocation\\MyGeo.gdb\\Updates\\Updates"+str(currentdate)
# Process: Make XY Event Layer
arcpy.MakeXYEventLayer_management(Changes, "longitude", "latitude", Changes_Layer, "", "")
# Process: Feature To Point
arcpy.FeatureToPoint_management(Changes_Layer, Updates, "CENTROID")
#Add layer into primary map document
addLayer = Changes_Layer +str(currentdate)
mxd = arcpy.mapping.MapDocument("\\\\c:\myLocation\\MyMap.mxd
df = arcpy.mapping.ListDataFrames(mxd, "Update")[0]
arcpy.mapping.AddLayer(df, addLayer, "TOP")
The script also corrupts my mxd to the point I cannot save it.
have you tried this on a local drive to rule out network issues?