1>>> SubjectLyr = arcpy.mapping.Layer("Y:\\Notification Radius Pkgs\\Dave3\\Shapefiles\\Dave3Subject.shp") # use either \\ or / in paths 2>>> mxd = arcpy.mapping.MapDocument("CURRENT") 3>>> df = arcpy.mapping.ListDataFrames(mxd, "Radius Map")[0] 4>>> wPath = "Y:\\Notification Radius Pkgs\\" # same as in line 1 5>>> arcpy.mapping.AddLayer(df, SubjectLyr,"AUTO_ARRANGE") 6>>> SubjectLyr = arcpy.mapping.ListLayers(mxd, SubjectLyr.name, df)[0] # change reference to layer in mxd 7>>> sourceLayer = arcpy.mapping.Layer(wPath+"Setup10\\LayerFiles\\Subject.lyr") # same as in line 1 8>>> arcpy.mapping.UpdateLayer(df, SubjectLyr, sourceLayer, True)
SubjectLyr = arcpy.mapping.Layer(r"F:\\testFiles\\output\\Population23_KDens.lyr") mxd = arcpy.mapping.MapDocument("F:\\testFiles\\testMap.mxd") df = arcpy.mapping.ListDataFrames(mxd)[0] wPath = "F:\\testFiles\\output\\" # same as in line 1 #Add the layer to basemap arcpy.mapping.AddLayer(df, SubjectLyr,"AUTO_ARRANGE") #Update the layer SubjectLyr = arcpy.mapping.ListLayers(mxd, SubjectLyr.name, df)[0] # change reference to layer in mxd sourceLayer = arcpy.mapping.Layer(wPath+"templates\\template.lyr") # get template layer arcpy.mapping.UpdateLayer(df, SubjectLyr, sourceLayer, True) ###Zoom to selection df.zoomToSelectedFeatures() lyrExtent = SubjectLyr.getSelectedExtent() df.extent = lyrExtent arcpy.mapping.ExportToPDF(mxd, r"F:\\testFiles\\output\\Population23_KDens_Map.pdf") print('DONE!')
mxd = arcpy.mapping.MapDocument( path to mxd ) df = arcpy.mapping.ListDataFrames(mxd)[0] ###UpdateLayer requires a data frame reference (returns 1st df) lyrFile = arcpy.mapping.Layer( path to lyr file ) ###This is a lyr file with pre-authored symbology you will apply to layer lyr = arcpy.mapping.ListLayers(mxd, "layer name", df)[0] ###A reference to the shapefile layer in MXD you want to update. arcpy.mapping.UpdateLayer(df, lyr, lyrFile, True) ###This will update ONLY the symbology
SubjectLyr = arcpy.mapping.Layer("Y:\Notification Radius Pkgs\Dave3\Shapefiles\Dave3Subject.shp") mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDataFrames(mxd, "Radius Map")[0] wPath = "Y:\Notification Radius Pkgs\\" arcpy.mapping.AddLayer(df, SubjectLyr,"AUTO_ARRANGE") sourceLayer = arcpy.mapping.Layer(wPath+"Setup10\LayerFiles\Subject.lyr") arcpy.mapping.UpdateLayer(df, SubjectLyr, sourceLayer, True)
>>> SubjectLyr = arcpy.mapping.Layer("Y:\\Notification Radius Pkgs\\Dave3\\Shapefiles\\Dave3Subject.shp") >>> mxd = arcpy.mapping.MapDocument("CURRENT") >>> df = arcpy.mapping.ListDataFrames(mxd, "Radius Map")[0] >>> wPath = "Y:\\Notification Radius Pkgs\\" >>> arcpy.mapping.AddLayer(df, SubjectLyr,"AUTO_ARRANGE") >>> SubjectLyr = arcpy.mapping.ListLayers(mxd, SubjectLyr.name, df) >>> sourceLayer = arcpy.mapping.Layer(wPath+"Setup10\\LayerFiles\\Subject.lyr")[0] Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> TypeError: 'Layer' object does not support indexing #####Okay - get rid of the index >>> sourceLayer = arcpy.mapping.Layer(wPath+"Setup10\\LayerFiles\\Subject.lyr") >>> arcpy.mapping.UpdateLayer(df, SubjectLyr, sourceLayer, True) Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\mapping.py", line 1868, in UpdateLayer assert isinstance(update_layer, Layer) AssertionError >>> arcpy.mapping.Layer(wPath+"Setup10\LayerFiles\Subject.lyr") <map layer u'Dave502Subject'> >>> arcpy.mapping.UpdateLayer(df, SubjectLyr, sourceLayer, True) Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\mapping.py", line 1868, in UpdateLayer assert isinstance(update_layer, Layer) AssertionError ####What are the values of the variables? >>> print SubjectLyr [<map layer u'Dave3Subject'>] >>> print sourceLayer Dave502Subject
1>>> SubjectLyr = arcpy.mapping.Layer("Y:\\Notification Radius Pkgs\\Dave3\\Shapefiles\\Dave3Subject.shp") # use either \\ or / in paths 2>>> mxd = arcpy.mapping.MapDocument("CURRENT") 3>>> df = arcpy.mapping.ListDataFrames(mxd, "Radius Map")[0] 4>>> wPath = "Y:\\Notification Radius Pkgs\\" # same as in line 1 5>>> arcpy.mapping.AddLayer(df, SubjectLyr,"AUTO_ARRANGE") 6>>> SubjectLyr = arcpy.mapping.ListLayers(mxd, SubjectLyr.name, df) # change reference to layer in mxd 7>>> sourceLayer = arcpy.mapping.Layer(wPath+"Setup10\\LayerFiles\\Subject.lyr")[0] # same as in line 1 8>>> arcpy.mapping.UpdateLayer(df, SubjectLyr, sourceLayer, True)
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.