I am having a difficulty adding representation applied feature class to mxd using ArcPy. The below code adds representation to the feature class, but the resulting map doesn't show applied representation instead, it adds 'Single symbol'. Do I have to save it to .lyr after adding representation layer to feature class in order to add it to mxd? I prefer not to create another layer, but if it is the only way, would you please tell me how to save the representation added feature class to .lyr? I tried to save the same to .lyr (SaveToLayerFile_management), but it wasn't successful. I would very much appreciate if you could provide me any assistance.
Note: Please ignore typos in below code.
import arcpy
arcpy.env.workspace = 'C:/data/data.gdb'
out_fc = 'lines'
relocate_rep = 'C:/data/relocate_rep'
mxd = "path to mxd file"
dfs = arcpy.mapping.ListDataFrames(mxd)
# Add representation
arcpy.AddRepresentation_cartography(out_fc, out_fc + '_Rep', 'RuleID', 'Override', 'STORE_CHANGE_AS_OVERRIDE',relocate_rep, 'ASSIGN')
arcpy.CalculateField_management(out_fc, 'RuleID', '!symbolID!', 'PYTHON_9.3')
# Add to mxd
lyr = arcpy.mapping.Layer(out_fc)
arcpy.mapping.AddLayer(dfs[0], lyr, 'AUTO_ARRANGE')
mxd.save()
del mxd
I figured out that what I needed was use of arcpy.MakeFeatureLayer_management and arcpy.SetLayerRepresentation_cartography after adding representations.
Thank you.