Convert arcmap to ArcGIS PRO - scripts

2500
12
Jump to solution
11-23-2021 10:49 AM
SoratoSouza_e_Silva
Occasional Contributor II

Hi,

Is there any practical way to convert scripts from arcmap to arcgis pro?

I need to convert several scripts, and for example this snippet I'm having a lot of problems.

arcpy.CalculateField_management("temp_informe_Layer", "EST_SUBREP", "" + anoAtual + " - Right( [PLANTIO],4 )", "VB", "")

would anyone know help me with the correct syntax for Arcgis PRO?

Thank´s

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

If it is a date field, you can use python expressions to work with dates, or more simply convert it to a string representation prior to slicing

assume datetime.datetime.now represents !PLANTIO!

import datetime

datetime.datetime.now()
Out[2]: datetime.datetime(2021, 11, 23, 16, 42, 51, 182197)

str(datetime.datetime.now())  # str(!PLANTIO!)  *****
Out[3]: '2021-11-23 16:43:08.012047'

str(datetime.datetime.now())[:4]  # str(!PLANTIO!)[:4]  *****
Out[4]: '2021'  # the year

... sort of retired...

View solution in original post

12 Replies
MichaelVolz
Esteemed Contributor

How about create a simple model in Pro using that specific query and see what the python export script looks like?

SoratoSouza_e_Silva
Occasional Contributor II

My problem is basically converting this snippet that is in VB and I can't find similar in PRO. This is a date field, and it says I can't slice a date field.

- Right( [PLANTIO],4 )

JayantaPoddar
MVP Esteemed Contributor

VB is not supported in ArcGIS Pro.

Try PYTHON3, ARCADE or SQL.

e.g.

!PLANTIO![-4:]

Also Replace "VB" with "PYTHON3"



Think Location
SoratoSouza_e_Silva
Occasional Contributor II

My problem is basically converting this snippet that is in VB and I can't find similar in PRO. This is a date field, and it says I can't slice a date field.

- Right( [PLANTIO],4 )

by Anonymous User
Not applicable

Hello SoratoSouza_e_Silva,

ArcMap uses Python 2 while ArcGIS Pro use Python 3. Many scripts will still be functional, but some will not. Esri and Python.org has some documentation that discusses the change. See below:

Python migration from 10.x to ArcGIS Pro

  • Some general information about the change plus extra resources.

Analyze Tools for Pro (Data Management)

  • A data management geoprocessing tool that can identify potential scripts that will have a problem running successfully.

2to3 - Automated Python 2 to 3 code translation

  • A command line utility to convert Python 2 code to Python 3 code.

I'd make sure to read up on any other these before making changes (especially the 2to3 command line utility). For safety, I'd recommend making a copy of the script(s) and making changes to the copy rather than the original.

I hope this is helpful and have fun!

Cheers,

Mike

 

DanPatterson
MVP Esteemed Contributor

If it is a date field, you can use python expressions to work with dates, or more simply convert it to a string representation prior to slicing

assume datetime.datetime.now represents !PLANTIO!

import datetime

datetime.datetime.now()
Out[2]: datetime.datetime(2021, 11, 23, 16, 42, 51, 182197)

str(datetime.datetime.now())  # str(!PLANTIO!)  *****
Out[3]: '2021-11-23 16:43:08.012047'

str(datetime.datetime.now())[:4]  # str(!PLANTIO!)[:4]  *****
Out[4]: '2021'  # the year

... sort of retired...
SoratoSouza_e_Silva
Occasional Contributor II

Thank you so much, you are fantastic...

But I think I wasn't very clear, I'll need to do a numerical count, and I can't subtract string:

arcpy.CalculateField_management("temp_informe_Layer", "EST_SUBREP", "" + anoAtual + " -  Right( [PLANTIO],4 )", "VB", "")

My data format is 23/11/2021

0 Kudos
DanPatterson
MVP Esteemed Contributor

still not clear since I don't know what the values are or what they represent, but if you have a number and a string and you want to subtract them, then

anoAtual = 100

fld = "2000"

anoAtual - int(fld)
-1900


... sort of retired...