import arcpymxd = arcpy.mapping.MapDocument("Current")df = arcpy.mapping.ListDataFrames(mxd)[0]layers = arcpy.mapping.ListLayers(mxd)myDir = 'H:/Analysis/ESRI/Sean/Help/' ##the directory where you want your lyr files placedfor layer in layers:[INDENT] layerFile = myDir + str(layer) + 'lyr' arcpy.SaveToLayerFile_management(layer, layerFile) [/INDENT]
to import arcypy, globmyImages = glob.glob('C:/YourDirectory/*.jpg') ## or whatever the extension isfor myImage in myImages:~~image = arcpy.mapping.Layer(myImage)~~imageAsLayer = image[:-3] + 'lyr' ## this cuts off the extension, and adds .lyr for the new filename~~arcpy.mapping.SaveToLayerFile_management(image, imageAsLayer)
But this is creating a new problem. All my raster data is georeferenced by TFW's and I guess that I will lose my reference if I create .lyr out of my image files...
import arcypy, globmyImages = glob.glob('C:/YourDirectory/*.jpg') ## or whatever the extension isfor myImage in myImages:~~image = arcpy.mapping.Layer(myImage)~~imageAsLayer = image[:-3] + 'lyr' ## this cuts off the extension, and adds .lyr for the new filename~~arcpy.mapping.SaveToLayerFile_management(image, imageAsLayer)
import arcpymxd = arcpy.mapping.MapDocument("Current")df = arcpy.mapping.ListDataFrames(mxd)[0]rows = arcpy.SearchCursor('c:/yourdirectory/index.shp')fields = arcpy.ListFields('c:/yourdirectory/index.shp')for row in rows:~~for field in fields:~~~~if field.name == 'Hyperlink':~~~~~~value = row.getValue(field.name)~~~~~~value = value[:-3] + 'lyr'~~~~~~addLayer = arcpy.mapping.Layer(value)~~~~~~arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
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.