The string is not working. I suspect that is because I asked the wrong question. I have an Annotation Feature Class that is displaying the information as integers within ArcMap, but the field type is a string.
Than the text should be calculated to a simple Python calculation of:
"(" + !AnnoText! + ")"
where you are calculating the annotation text field and that text field name is AnnoText. Change AnnoText to match your actual annotation text field name.
The same simple calculation in VB Script is:
"(" & [AnnoText] & ")"
I changed the text to match my field name. My field name is TextString. So, my line of script reads:
"(" + !TextString! + ")"
But, a Syntax Error is returned. Changing the outer double quotes to single quotes eliminates the syntax error, yet does not add the parentheses. I have a couple of Annotation Feature Classes with the field TextString. Then, I attempted to specify which Feature Class to apply the parentheses.
'(" + (History)!TextString! + ")'
The script does not have any errors. Yet, does not add the parentheses.
I have no idea what you think you were doing in the second calculation, but that version definitely should not work. Aren't you just using a single feature class for the anno? If two feature classes are involved you never mentioned that.
Screen shot the table and the field calculator dialog set up you used with my original expression. I want to see exactly what you have and what you did.
Use the Field Calculator field list to build the expression and to insert the field name in the calculation. Quotes should be fine, but so should single quotes (only for Python, not for VB Script).
I am running a similiar script to copy & paste annotations, which is why I posted in this thread. The copy & paste part of my script works fine. I have two annotation Feature Classes, but only want the parentheses added to one Annotation Feature Class. Which, is why I attempted to specify the Feature Class to add the parentheses. I probably should have set up a conditional statement.
Your suggestion of "(" + !TextString! + ")" works using Field Calculator. Parentheses are added to selected values within the TextString field.
def AddParentheses(TextString): Output = TextString if Output[0] != "(": Output = "(" + Output + ")" return Output
jdrvar;329266 wrote:
I changed the text to match my field name. My field name is TextString. So, my line of script reads:
TextString = arcpy.GetParameterAsText(0) addParentheses = "(" + TextString + ")" cursor = arcpy.da.UpdateCursor(History, ["TextString"]) for row in cursor: row[0] = addParentheses cursor.updateRow(row) del row del cursor
jdrvar;329266 wrote:
I changed the text to match my field name. My field name is TextString. So, my line of script reads:
"(" + !TextString! + ")"QUOTE]
addParentheses = "(" + !TextString! + ")" returns a Syntax Error. I know the field name and type are correct, therefore, believed the expression to be correct. That left the concatenation of parentheses. But, the concatenation worked within Field Calculator. Then, I went back reread the posts and tried adding a second variable; expression = (!TextString!). Which also created a Syntax Error. So, I removed the exclamation points from the addParentheses variable. Removing the exclamation points, the script runs, and replaces existing text with parentheses. But, I want to concatenate the existing text with parentheses. Any suggestions?TextString = arcpy.GetParameterAsText(0) addParentheses = "(" + TextString + ")" cursor = arcpy.da.UpdateCursor(History, ["TextString"]) for row in cursor: row[0] = addParentheses cursor.updateRow(row) del row del cursor
Well this is nothing like a Field Calculation, so of course the !TextString! won't work. I did not know you were going to this kind of script. Just use the updatecursor itself to do this.FieldName = arcpy.GetParameterAsText(0) cursor = arcpy.da.UpdateCursor(History, [FieldName]) for row in cursor: row[0] = "(" + row[0] + ")" cursor.updateRow(row) del row del cursor
The input parameter would be any text field name. So choose "TextString" in that parameter. Or forget the parameter and hard code the field name.cursor = arcpy.da.UpdateCursor(History, ["TextString"]) for row in cursor: row[0] = "(" + row[0] + ")" cursor.updateRow(row) del row del cursor
jdrvar;330609 wrote:
Well this is nothing like a Field Calculation, so of course the !TextString! won't work. I did not know you were going to this kind of script. Just use the updatecursor itself to do this.FieldName = arcpy.GetParameterAsText(0) cursor = arcpy.da.UpdateCursor(History, [FieldName]) for row in cursor: row[0] = "(" + row[0] + ")" cursor.updateRow(row) del row del cursor
The input parameter would be any text field name. So choose "TextString" in that parameter. Or forget the parameter and hard code the field name.cursor = arcpy.da.UpdateCursor(History, ["TextString"]) for row in cursor: row[0] = "(" + row[0] + ")" cursor.updateRow(row) del row del cursor
I suppose I should have been more specific. Using your suggestion works! I just need to refresh to display the ().arcpy.RefreshActiveView()