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
Solved! Go to Solution.
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
How about create a simple model in Pro using that specific query and see what the python export script looks like?
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 )
VB is not supported in ArcGIS Pro.
Try PYTHON3, ARCADE or SQL.
e.g.
!PLANTIO![-4:]
Also Replace "VB" with "PYTHON3"
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 )
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
Analyze Tools for Pro (Data Management)
2to3 - Automated Python 2 to 3 code translation
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
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
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
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