Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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)
lyr2.saveACopy(93File,'9.3')

...

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.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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
lyr.saveACopy(93File,'9.3')
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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