The code returns me an error
Runtime error <type 'exceptions.IOError'>: UNKNOWN
layerName=r'M:\UTILISATEURS\Pierre\SERAIL\MISE_A_JOUR.gdb\TEST'
I work from a class annotation. I don�??t want to change the data source, but simply change the label expression or display rather like my data is a class annotation.
Hi Pierre,I notice your layername. I used the name of the layer as it appears in the table of contents (TOC) of the mxd. You are using a reference to the data source itself and that's probably not how the layer is named in the TOC. So change this:layerName=r'M:\UTILISATEURS\Pierre\SERAIL\MISE_A_JOUR.gdb\TEST'
to this:layerName='TEST'
... if your layer is called 'TEST' in the TOC.You could also try with manually entering the label expression below in the layer properties:replace(replace([TEXTSTRING],"Ec.","Ecole"),"Egl.","Eglise")The error Runtime error <type 'exceptions.IOError'>: UNKNOWN you obtained refers to:Raised when an I/O operation (such as a print statement, the built-in open() function or a method of a file object) fails for an I/O-related reason, e.g., "file not found" or "disk full".
Do you have write permissions to save the mxd?But the biggest difference is that you are not labeling based on a field, but you have an (feature-linked?) annotation class. This works completely different. In stead of a label expression there is the "Display Expression". This display expression is not (yet) supported by arcpy. In this case the best thing you can do is manually enter the properties of the annotation class and activate the Display TAB and press the Expression button:[ATTACH=CONFIG]28710[/ATTACH]In the Display Expression dialog enter the expression:replace(replace([TEXTSTRING],"Ec.","Ecole"),"Egl.","Eglise")[ATTACH=CONFIG]28711[/ATTACH]When there are more parts of text you want to change in the feature, it may be better to use a multiline expression like this:Function FindLabel ( [TextString] )
Label = replace([TextString], "Ec.", "Ecole")
Label = replace(Label, "Egl.", "Eglise")
Label = replace(Label, "Text to search for", "Text to replace it with")
'etc
FindLabel = Label
End Function
I tried this with a dummy dataset and if I hit the "Verify" button it shows the replaced text correctly. If I look at the map however it doesn't display the changed text. Please note that I switched on the option "Show MapTips using the display expression"... See steps below.[ATTACH=CONFIG]28714[/ATTACH]What is even stranger, when I hover over the text in the map it shows a kind of tool tip with the corrected text...This is odd.. maybe you're better of not using annotation...Kind regards,Xander