Hello everyone, I need to run an ArcMap script (VBScript) in ArcGis Pro, but I get an error. Do you know why it gives me that problem? Kind regards.
Solved! Go to Solution.
Can you post your script?
FYI, vbscript was only implemented in ArcGIS Pro as of version 3.2.
Support VB expressions in Calculate Field
This is the full script, and yes, I am using version 3.2. I want to adapt it to the Arcgis pro 3.2 version.
Hi Jairo,
So, It looked like your code just checked the values in a field and returned the same values. I'm not sure why you were doing that.
You can do a conditional field calculation like this:
This example shows two text fields with string representations of numbers between 1 and 10, and some 998 values. If the value in the source field, "A_field" is equal to "1" or "2" it returns those values to the target field ("A_second_field"), and if it is "998" it returns "998".
A Python function, that I named "my_conditional" takes a single variable parameter (the source field) and returns some values using conditional evaluation.
The result is:
Notice that values of 1, 2, and 998 get added to the target field, and the other rows have their original value of <Null>.
Another thing you could do calculate all of the values in the second field to be the same as the values in the source field. You don't need any Python code for this:
The result is:
Another thing you might do is use Python to convert integer values in one field to string values in the target field. Here I convert the integer values form OBJECTID field into strings in the target field:
That tutorial I gave you a link for shows step-by-step how to add a new function and use it to calculate values.
Best,
Bob
Do the two fields have coded value domains? If so, modify the script so it looks for and sets the coded value.
SO, instead of looking for "FUERTE", look for 6, and instead of setting the value of ">40 - 70%", set the value of 6.
Check the fields to determine the data type. For text codes, use "6" in quotation marks, and for integer codes use the value 6 without quotation marks.
can you convert the script to Python? I never could get vbScripts to work in ArcGIS Pro.
Can you post your script?
FYI, vbscript was only implemented in ArcGIS Pro as of version 3.2.
Support VB expressions in Calculate Field
This looks like a conditional field calculation.
You can rebuild it in Python. See the examples here:
https://pro.arcgis.com/en/pro-app/3.1/tool-reference/data-management/calculate-field-examples.htm
Here is a link to a bit of a tutorial showing a similar field calculation:
Hi Jairo,
So, It looked like your code just checked the values in a field and returned the same values. I'm not sure why you were doing that.
You can do a conditional field calculation like this:
This example shows two text fields with string representations of numbers between 1 and 10, and some 998 values. If the value in the source field, "A_field" is equal to "1" or "2" it returns those values to the target field ("A_second_field"), and if it is "998" it returns "998".
A Python function, that I named "my_conditional" takes a single variable parameter (the source field) and returns some values using conditional evaluation.
The result is:
Notice that values of 1, 2, and 998 get added to the target field, and the other rows have their original value of <Null>.
Another thing you could do calculate all of the values in the second field to be the same as the values in the source field. You don't need any Python code for this:
The result is:
Another thing you might do is use Python to convert integer values in one field to string values in the target field. Here I convert the integer values form OBJECTID field into strings in the target field:
That tutorial I gave you a link for shows step-by-step how to add a new function and use it to calculate values.
Best,
Bob
Hello Bob,
I'll explain it to you another way, I'm using a cataloged GDB that has two fields: RPDT and DECS_RPDT.
This "RPDT" field contains slope ranges used in Geomorphology, and the other field "DECS_RPDT" contains the text that corresponds to the ranges contained in the "RPDT" field. (see image 1).
When I do the photointerpretation, I enter the range of the "RPDT" slope, and the script instead, when I execute it, adds the qualitative value that corresponds to each range. (see image 2).
Hence, it is not as you indicated above, that I copy the same value into another field.
Seriously, I am very grateful to you, I already copied it with all the values, but it fills the "DECS_RPDT" field as NULL.
I hope it's clearer, and sorry for the inconvenience.
Do the two fields have coded value domains? If so, modify the script so it looks for and sets the coded value.
SO, instead of looking for "FUERTE", look for 6, and instead of setting the value of ">40 - 70%", set the value of 6.
Check the fields to determine the data type. For text codes, use "6" in quotation marks, and for integer codes use the value 6 without quotation marks.