Select to view content in your preferred language

Edit an Arcmap Script to be used in ArcGIS Pro

1641
9
Jump to solution
04-03-2024 12:10 PM
Labels (1)
JairoCordero
New Contributor III

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.

Tags (3)
0 Kudos
5 Solutions

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Can you post your script?

View solution in original post

0 Kudos
Bud
by
Honored Contributor

FYI, vbscript was only implemented in ArcGIS Pro as of version 3.2.

Support VB expressions in Calculate Field

 

View solution in original post

0 Kudos
JairoCordero
New Contributor III

JairoCordero_0-1712235709827.png

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.

View solution in original post

0 Kudos
BobBooth1
Esri Contributor

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:

conditional_calc_a.png

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:

conditional_calc_a_result.png

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:

Calc_no_cond_b.png

The result is:

Calc_no_cond_b_result.png

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:

calc_integer_value_to_string_value.png

 

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

View solution in original post

BobBooth1
Esri Contributor

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.

View solution in original post

0 Kudos
9 Replies
SLouq
by MVP Regular Contributor
MVP Regular Contributor

can you convert the script to Python? I never could get vbScripts to work in ArcGIS Pro.

0 Kudos
KenBuja
MVP Esteemed Contributor

Can you post your script?

0 Kudos
Bud
by
Honored Contributor

FYI, vbscript was only implemented in ArcGIS Pro as of version 3.2.

Support VB expressions in Calculate Field

 

0 Kudos
JairoCordero
New Contributor III

JairoCordero_0-1712235709827.png

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.

0 Kudos
BobBooth1
Esri Contributor

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:

https://learn.arcgis.com/en/projects/identify-schools-for-a-mentoring-program/#:~:text=use%20a%20fie...

0 Kudos
JairoCordero
New Contributor III

Hello, I'm not a programmer so I don't know what commands to use. There will be the possibility that you can help me by modifying just one part, from there I think I know how to modify the rest. I would be very grateful to you. Kind regards. 

Please.

0 Kudos
BobBooth1
Esri Contributor

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:

conditional_calc_a.png

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:

conditional_calc_a_result.png

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:

Calc_no_cond_b.png

The result is:

Calc_no_cond_b_result.png

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:

calc_integer_value_to_string_value.png

 

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

JairoCordero
New Contributor III

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).

JairoCordero_0-1712597272347.jpeg

 

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).

JairoCordero_1-1712597287742.jpeg

 

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.

0 Kudos
BobBooth1
Esri Contributor

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.

0 Kudos