AnsweredAssumed Answered

Replace() string function isn't working within Field Calculator and arcpy

Question asked by durshe on Nov 23, 2015
Latest reply on Nov 24, 2015 by durshe

I'm trying to figure out what's wrong with my python syntax.

 

I have an attribute table with 4 fields containing paths to media files. I'm trying to convert the paths so that they behave more like hyperlinks on our network. The existing paths (added to the tables via 3rd party proprietary software) include network drive i.e. M:\GraniteXP\...

 

I'm trying to use find and replace to replace "M:\GraniteXP" with "\\vancouver.root.local\...\GraniteXP".

 

I can do this perfectly fine using field calculator in ArcMap as well as Model Builder. However, when I export the model to Python; the script runs (successfully), but the values are not updated. There is not error to tell me what's failing.

 

Here's a snippet from my script. I do have a MakeFeatureLayer prior to this snippet. (Note: this particular script is trying to change it back to the network drive pathing for testing purposes).

 

arcpy.SelectLayerByAttribute_management("lyrsdePipeInsp", "NEW_SELECTION", "Photo1 is not null")

arcpy.CalculateField_management("lyrsdePipeInsp", "Photo1", "Replace( [Photo1], \"\\\\vancouver.root.local\\cityapps\\GraniteXP\", \"M:\\GraniteXP\" )", "VB", "")

 

arcpy.SelectLayerByAttribute_management("lyrsdePipeInsp", "NEW_SELECTION", "Photo2 is not null")

    arcpy.CalculateField_management("lyrsdePipeInsp", "Photo2", "Replace( [Photo2],  \"\\\\vancouver.root.local\\cityapps\\GraniteXP\", \"M:\\GraniteXP\" )", "VB", "")

 

arcpy.SelectLayerByAttribute_management("lyrsdePipeInsp", "NEW_SELECTION", "Photo3 is not null")

arcpy.CalculateField_management("lyrsdePipeInsp", "Photo3", "Replace( [Photo3], \"\\\\vancouver.root.local\\cityapps\\GraniteXP\", \"M:\\GraniteXP\" )", "VB", "")

 

arcpy.SelectLayerByAttribute_management("lyrsdePipeInsp", "NEW_SELECTION", "Video is not null")

arcpy.CalculateField_management("lyrsdePipeInsp", "Video", "Replace( [Video], \"\\\\vancouver.root.local\\cityapps\\GraniteXP\", \"M:\\GraniteXP\" )", "VB", "")

 

Thanks!

Eugene Durshpek

Outcomes