Not sure if this is possible - I am writing a python script to convert LYR files to use relative paths and save the LYR as a 9.3 LYR file. I can do each one individually, but not together.


# save existing LYR to a new file and set to RELATIVE path - works
arcpy.SaveToLayerFile_management(lyr, relFile, "RELATIVE")

# saveACopy to v9.3 LYR file - works, but does not maintain RELATIVE path
lyr2 = arcpy.mapping.Layer(relFile)


It doesn't seem to matter if I reverse the order of these calls, I still get v9.3 LYRs with absolute paths and v10.x LYRs with relative paths. I have run this in 10.0 and 10.1 and see the same results.


In the process of getting this ready to post, I figured it out! Posted anyway in case this might be helpful to others.

I needed to do both the relative path setting and v9.3 export in one step to make them both stick. So I created an MXD with relative paths set, inserted my old LYR into it, and then saveACopy'd it to v9.3. This last step brings along the relative path setting from the MXD.

mxd = arcpy.mapping.MapDocument(r'LYR_MXD.mxd')
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]

# add existing LYR file
arcpy.mapping.AddLayer(df, lyr, "AUTO_ARRANGE")

# save to a new LYR file - set to new Relative path
# not sure why this is needed, but the next step won't work without it
arcpy.SaveToLayerFile_management(lyr, relFile, "RELATIVE")

# save to a new LYR file at v9.3 - this takes the Relative setting from the MXD

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.