Hi everyone,
Very new to ModelBuilder - I am trying to use ModelBuilder to add a field called “Survey_ID” then populate that field using Calculate Field to use the last 6 characters of the filename for a group of feature classes. The Iterate Feature Classes and Add Field options seem to be working, but my Calculate Field expression seems to be incorrect. Here is the error I get when I run the model:
Executing (Calculate Field): CalculateField "O:\DCF\Test HerringAS Geodatabase.gdb\HAS_Photo_0325_201702" Survey_ID Right('HAS_Photo_0325_201702', 6) VB #
Start Time: Thu Apr 13 09:16:24 2017
General error executing calculator.
ERROR 999999: Error executing function.
Syntax error
Failed to execute (Calculate Field).
For the Calculate Field I hit the Calculator icon, and in the box for Survey_ID = I use this expression: Right('%Name%', 6)
Any idea what I’m doing wrong here?
Thanks so much for any assistance!
Solved! Go to Solution.
Solved it! I used " instead ' around %Name% and it appears to be working. Thanks for the help everyone.
An initial observation is that it appears that the Geodatabase has spaces in the name. If that is the case, see if you can change the Geodatabase name using underscores instead of spaces. There are quite a few processes in GIS that choke when a space is used in a filename or folder name, and unfortunately there is not a helpful error message that pops up to notify the user of this.
Also, a question. Does the same issue occur if one does the Calculate Field manually? In other words, does it work when done manually, but does not work when employed through Modelbuilder?
Chris Donohue, GISP
I tried renaming the Geodatabase and I get a "Failed to rename object" error. It's interesting that the Add Field works fine, but the Calculate Field doesn't since they both reference the same Geodatabase.
Solved the rename issue with the Geodatabase, but still receiving the syntax error on the Calculate Field.
Hi Shane, to mention a few of the things I mention in the email (that Chris hasn't already)
"... Do you have write permissions to the featureclass/table? Is the field able to accept a string format? Maybe you need to convert the result of Right() to a value. Also, make sure all your CaSe is correct. I think VB might be more forgiving, but python is not."
edit: tagging https://community.esri.com/groups/model-builder?sr=search&searchId=295e6fc7-372b-4211-a594-f08f71035...
We can move the discussion here instead of email so anyone who might be able to assist is privy to all the information, good idea. From my recent email:
I renamed the Geodatabase to take the spaces out but I’m still receiving the syntax error. Even though the end result of the Field would be a 6 digit number, I have the Add Field set up to make it a Text field so that it can accept strings. I am able to edit the table and make changes so I believe my write permissions are ok.
I would try a manual entry using field calculator outside of the model, but I’m not sure how to get the field calculator to reference the filename when it is not a field in the table nor an inline variable in ModelBuilder.
Solved it! I used " instead ' around %Name% and it appears to be working. Thanks for the help everyone.
….glad you got it fixed….i in geonet, remember to close out your thread by maybe comments that are helpful, and the one that is correct. You don’t get points for marking your own, but still probably the best one to mark. Other option is to mark it as assumed answered. Same point results, but both let others know it was resolved.
Geonet etiquette. ☺
A better solution is to use Python! A side benefit is this (besides Python being awesome) will allow your model to run in Pro ( VBScript is not supported in 64 bit.) Use the PYTHON_9.3 parser and this syntax, either single or double quotes:
"%Name%"[-6:]
Python definitely seems like a skillset I want to develop, when I've got some more time to devote to studying I plan to do so. Thanks for the help!