hello everyone,
i am using arcgis pro 2.4. I am trying to change the values of an attribute suing model builder calculate fiend tool. however, I am getting an error when I run the tool. Below is a screen shot of what i am using and getting error 000539. Any thoughts or suggestions on how i can overcome this would be highly appreciated.
thank you.
Solved! Go to Solution.
This is the solution I worked out:
I ran the spatial joins and plain joins before manipulating the data. One thing to consider is the data type of the attribute to have its values replaced and the data type of the attribute to have its values compared to the first one. In this case the attribute to have the values changed is numeric and the other to be compared against is text. To be able to compare the 2 attributes they need to be of the same data type. So a new attribute has to be created with a text data type. Next the values from the original attribute are copied into the newly created attribute. Finally, the values can be replaced as required. See below for screen shots.
1 - From the geoprocessing pane drag the "Add Field" tool from the data management tools.
2 - Once the new filed is created, drag a "Calculate Field" tool from the data management tools. Use expression type Arcade and then insert the attribute you want to copy values from right at the bottom by double clicking it in the "fields" list.
3 - Now that the values have been copied into the newly created attribute, drag another "Calculate Field" tool from the data management tools. This one will do the replacement of the values in the newly created attribute. By using the Arcade code expression right at the bottom. This uses the creation of a variable and a conditional "if" statement to find and replace values accordingly. PS - I had no null values in my data but if you do then you will need to adjust the statement to cater for nulls.
4 - Now that the data is comparable, drag a "Select" from the Analysis tools. Fill in the SQL expression and away you go...
Thank you to all who took the time to read and attempted to help.
Cheers.
Screenshot of full error message?
what you did is wrong. you have to write the in a function in Code Block section, then call it .
try this:
Fire_Risk_T=
replace_func(!Fire_Risk_T!,"1","HBLCA")
=====Code Block====
def replace_func(field, old_text,new_text):
return field.replace(old_text,new_text)
Documentation for Calculate Value tool in ModelBuilder:
https://pro.arcgis.com/en/pro-app/latest/tool-reference/modelbuilder-toolbox/calculate-value.htm
I assume !Fire_Risk_T! field has a Text datatype. If not, please create a new field with Text DataType and use Field Calculator on that field.
Check the following expression
!Fire_Risk_T!.replace("1","HBLCA")
hey thanks for your help.
I had done that already. In fact, I already finished creating the model and it works nicely!
Maybe I should document it here how I did it in case others come across the same problem.
thank you.
That would be in fact helpful if you would share your solution here.
And then except it as solution so the post is marked as solved.
Hi Nicole,
I will reply with the solution detailed. Sorry, I had one of those moments when you lose it all and had to start from scratch again. Lucky I have a good memory and could put it together again. Stay tuned.
thanks.
This is the solution I worked out:
I ran the spatial joins and plain joins before manipulating the data. One thing to consider is the data type of the attribute to have its values replaced and the data type of the attribute to have its values compared to the first one. In this case the attribute to have the values changed is numeric and the other to be compared against is text. To be able to compare the 2 attributes they need to be of the same data type. So a new attribute has to be created with a text data type. Next the values from the original attribute are copied into the newly created attribute. Finally, the values can be replaced as required. See below for screen shots.
1 - From the geoprocessing pane drag the "Add Field" tool from the data management tools.
2 - Once the new filed is created, drag a "Calculate Field" tool from the data management tools. Use expression type Arcade and then insert the attribute you want to copy values from right at the bottom by double clicking it in the "fields" list.
3 - Now that the values have been copied into the newly created attribute, drag another "Calculate Field" tool from the data management tools. This one will do the replacement of the values in the newly created attribute. By using the Arcade code expression right at the bottom. This uses the creation of a variable and a conditional "if" statement to find and replace values accordingly. PS - I had no null values in my data but if you do then you will need to adjust the statement to cater for nulls.
4 - Now that the data is comparable, drag a "Select" from the Analysis tools. Fill in the SQL expression and away you go...
Thank you to all who took the time to read and attempted to help.
Cheers.
Thanks for taking the time to document your solution!