Thanks Jake,The code you posted specifies a specific path to the shapefile to be added. However, if the name of the file changes, the script would not be able to be used repeatedly without updating the file name/path. Is there a way to add/convert the layer based only on the directory in which it resides? That way the process could be automated to convert and add which ever file exists in the directory at the time the script was run. Once the file is copied to a new directory, the process could be run on any new files that are moved into the directory that is referenced by the script.To further explain, I am creating a daily rountine to reformat shapefiles that are updated on a daily basis. The shapefiles are archived with a date in order to give them a unique name. However, the input file name is always the same until the date suffix is added. Once the suffix is added, the file name becomes unique, but the directory is always consistant. There will only ever be one file at a time in the directory where the processing is done. I am fairly new to python scripting so I apologize if I am not explaining this in the best way. For context, I've pasted the script below. Again, my apologies if the script seems a bit amateurish, but I am just geting started with the language:-)As you can see, the last step is to remove the layer with the generic name. I am getting hung up on performing any further processes once the file name becomes variable. Ideally, I could reference the file based on its directory rather than its file name since the file name will be variable at this point. mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd,"*")[0]
newlayer = arcpy.mapping.Layer("C:\pathname\detentio.shp")
arcpy.mapping.AddLayer(df, newlayer,"TOP")
arcpy.AddField_management ("detentio", "Date_Txt", "TEXT","","",10,"Date_Txt","NULLABLE","NON_REQUIRED","")
arcpy.CalculateField_management("detentio","Date_Txt","[Date_Visit]","VB","#")
arcpy.ConvertTimeField_management("detentio","Date_Txt","MM/dd/yyyy;1033;;","Date_Mod","TEXT","yyMMdd;1033;;")
arcpy.DeleteField_management("detentio","Date_Txt")
arcpy.AddField_management ("detentio", "PhotoName", "TEXT","","",40,"PhotoName","NULLABLE","NON_REQUIRED","")
arcpy.CalculateField_management ("detentio", "PhotoName","[Date_Mod]& Chr(95) & right([photo],10)","VB")
arcpy.AddField_management ("detentio", "PhotoPath", "TEXT","","",200,"PhotoPath","NULLABLE","NON_REQUIRED","")
arcpy.CalculateField_management ("detentio", "PhotoPath",'"V:\newpathname\\"&[PhotoName]',"VB")
arcpy.DeleteField_management("detentio",["PhotoName"])
arcpy.DeleteField_management("detentio",["photo"])
from arcpy import env
env.workspace = "C:\pathname"
fc = "detentio"
rows = arcpy.SearchCursor("detentio", "FID = 1")
for row in rows:
time = row.Date_Mod
del row, rows
arcpy.DeleteField_management("detentio",["Date_Mod"])
arcpy.Rename_management("detentio.shp", "detentio" + "_" + time, "ShapeFile")
mxd = arcpy.mapping.MapDocument("Current")
for df in arcpy.mapping.ListDataFrames(mxd):
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
if lyr.name.lower() == "detentio":
arcpy.mapping.RemoveLayer(df, lyr)
print "Processing Complete."
Thanks again for your help!- Pete