Support creation of NEW layer files in arcpy

82
1
09-17-2013 06:19 AM
Status: Open
DouglasSands1
New Contributor II
Expand arcpy.mapping to allow for users to create new lyr files programatically.

This would be useful as a script developer trying to share scripts accross an organization without having to maintain large numbers of files. Rather than making sure users are pointing to the current script, and have access to directories where neccessary layers are stored, the ability to create layer files directly within a .pyt file would enable easier sharing and maintenence.
1 Comment
JasonScheirer

Already possible:

new_layer_name = "mynewlyr"
new_layer_file = r"c:\my_new_layer.lyr"
arcpy.management.MakeFeatureLayer(r"c:\my.shp", new_layer_name)
lyr = arcpy.mapping.Layer(new_layer_name)
lyr.saveACopy(new_layer_file)

arcpy.management.Delete(new_layer_name)

You might want to have some .lyr sitting around with your desired symbology to apply to it, but this small code snippet will do what you want. Another idea is to have a .lyr with your symbology set and use replaceDataSource to point it to a new feature class, then saveACopy it.