1

I'm trying to do some work using Python 2.7 and ArcGIS Desktop 10.7.1 - I know old software. For some reason that I cannot figure out, my script adds the derived featureclass / shapefile and then when the script finishes, the layer is no longer in my TOC. I've tried many of the suggestions I have found on the internet and nothing will make it stick.

 # Accessing the current open ArcMap project. mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] '''addLayer = arcpy.mapping.Layer(PATH + os.sep + "sel_GVILandscapePolygon.shp")''' '''addLayer = arcpy.mapping.Layer(r"E:\Junk\GVI_Query\sel_GVILandscapePolygon.shp")''' FnShp = PATH + os.sep + "sel_GVILandscapePolygon.shp" addLayer = arcpy.mapping.Layer(FnShp) arcpy.mapping.AddLayer(df, addLayer, "TOP") arcpy.RefreshTOC() mxd.save() 

Any thoughts?

1 Answer 1

0

I never quite found out why my derived output would not stay in my TOC; however, I did get it work by returning my input path variable to the root of the script.

if __name__ == '__main__': # Return the Path variable from the main module. PATH = Main (arcpy) # Accessing the current open ArcMap project & dataframe. mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] # Create a vaiable to provide the pathway to the shapefile that I want to add to my map. FnShp = PATH + os.sep + "sel_GVILandscapePolygon.shp" # Add the layer, refresh the TOC and save the mxd. addLayer = arcpy.mapping.Layer(FnShp) arcpy.mapping.AddLayer(df, addLayer, "TOP") arcpy.RefreshTOC() mxd.save() # Clean up and terminate. del arcpy, mxd, df, FnShp, addLayer sys.exit(0) 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.